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"})