cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to Convert Jun 17, 2019 12:00 AM to 06/17/2019 format?

Shirali
New Contributor

I have tried using Date.parse() but it gives a NaN error.

3 REPLIES 3

Minovski
New Contributor II

Hi Shirali,

I have converted โ€œJun 17, 2019 12:00 AMโ€ into โ€œ06/17/2019โ€ .
This is solved in two ways in the Pipeline attached (ConvertDate_2019_09_30):

  • Solution with match expression, combined with slice() and replaceAll():

(match $date.slice(0,4){"Jan "=>โ€œ01/โ€,"Feb "=>โ€œ02/โ€,โ€œMarโ€=>โ€œ03/โ€,"Apr "=>โ€œ04/โ€,โ€œMayโ€=>โ€œ05/โ€,"Jun "=>โ€œ06/โ€,"Jul "=>โ€œ07/โ€,"Aug "=>โ€œ08/โ€,"Sep "=>โ€œ09/โ€,"Oct "=>โ€œ10/โ€,"Noe "=>โ€œ11/โ€,โ€œDec โ€œ=>โ€œ12/โ€,} + $date.slice(4,12).replaceAll(โ€, โ€œ,โ€/โ€))

  • Solution with combining multiple expressions ( startsWith(), .replaceAll(), slice() )
    PFA pipeline!
    ConvertDate_2019_09_30.slp (8.3 KB)

Regards,
Nikola Minovski

Thank you! This worked.

Shirali

tstack
Former Employee

You can specify the format to be used for parsing by passing it as the second argument to Date.parse(). The toLocaleDateTimeString() method can also take an optional parameter where you can specify the format to use when turning the date into a string:

Date.parse("Jun 17, 2019 12:00 AM", "MMM dd, yyyy hh:mm a")
    .toLocaleDateTimeString({format: "MM/dd/YYYY"})