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

Time format Conversion changing the date

Shrabanti
New Contributor II

I am doing date conversion. But not sure why it is changing the date.

Input Date is : โ€œ29-JUN-21 10.07.35.000000 AMโ€
Output date is becoming :โ€œ2020-12-27 10:07:35โ€

The conversion I am using is :
Date.parse($OrderDetailCreateDate,โ€œdd-MMM-YY hh.mm.ss.SSSSSS aaโ€).toLocaleDateTimeString( { โ€œformatโ€:โ€œyyyy-MM-dd HH:mm:ssโ€ } )

2 REPLIES 2

Sowmya_Rayavara
New Contributor III

Hi Shrabanti,

Can you please try with the below date function? Just changed the year format โ€˜YYโ€™ to โ€˜yyโ€™

Date.parse(โ€œ29-JUN-21 10.07.35.000000 AMโ€,โ€œdd-MMM-yy hh.mm.ss.SSSSSS aaโ€).toLocaleDateTimeString( { โ€œformatโ€:โ€œyyyy-MM-dd HH:mm:ssโ€ } )

bojanvelevski
Valued Contributor

Hi @Shrabanti ,

Your expression looks good, and only needs 2 changes. Year should be lowercase letters, and Hours should be uppercase. The expression needs to look like this:

Date.parse('29-JUN-21 10.07.35.000000 AM','dd-MMM-yy HH.mm.ss.SSSSSS aa').toLocaleDateTimeString( { "format":"yyyy-MM-dd HH:mm:ss" } )

@Sowmya_Rayavarapuโ€™s expression is nearly identical, and also works.

Regards,
Bojan