parseDate not working with PM marker
When I parse dates that have AM and PM markers in the time, the AM markers work fine but the PM markers trigger the error "Unparseable date". Here are some examples that work and don't work:
| parseDate("08/03/2021 02:00:00 AM","MM/dd/yyyy HH:mm:ss a", "America/New_York" ) as ThisDateParseWorks
| parseDate("08/03/2021 14:00:00","MM/dd/yyyy HH:mm:ss", "America/New_York" ) as ThisDateParseWorks2
| parseDate("08/03/2021 02:00:00 PM","MM/dd/yyyy HH:mm:ss a", "America/New_York" ) as ThisDateParseDoesNotWork
The AM/PM do not appear to be case sensitive. Can you give me any tips on how to parse the "PM" marker successfully?
-
Hi Jamie Gangestad,
Within your format you'll want to change the hour designation from "HH" to "hh." Lowercase "hh" defines the hours are in am/pm (1-12) so should address the error you're seeing.| parseDate("08/03/2021 02:00:00 PM","MM/dd/yyyy hh:mm:ss a", "America/New_York" ) as ThisDateParseShouldWork
Uppercase "HH" designates that the parsed hour is in 24 hour format. (0-23) Since 02 in this format is always AM trying to define this as PM could be resulting in the error. You should also see a similar issue if in your first expression you change the time from 02 to 13.
Please sign in to leave a comment.
Comments
2 comments