How to convert String to Date format
Hi,
I have a requirement where I'm getting a value from response in string format i.e "15 Jul 2020". I wanted to map this value to a date property but When i map It's throwing an error saying" String can't be mapped to Date".
So need a function of format where i can map text to date property.
Thanks in advance
Akhil

I had a look through the Functions associated with the DateTime Library and there doesn't appear to be one that does what you need. You may find a combination to chain together that appears to do what you need, however as I expect you want to keep timestamps and timezones out of it, I would caution against the OTB Pega DateTime Functions for date-only conversion as most do some sort of conversion to a timestamp, which risks a timezone conversion changing your date portion back a day if you are running in a timezone east of GMT.
For a few lines of Java, you may be better off implementing your own Function. If you are on a Java 8 (or higher) JVM, the new java.time.LocalDate and java.time.format.DateTimeFormatter classes are ideal for doing this conversion without involving times and timezones.
If you had:
(e.g. "d MMM yyyy", you may need "dd MMM yyyy" if the day portion is zero-padded when less than 10)
The Function would be something like:
I had a look through the Functions associated with the DateTime Library and there doesn't appear to be one that does what you need. You may find a combination to chain together that appears to do what you need, however as I expect you want to keep timestamps and timezones out of it, I would caution against the OTB Pega DateTime Functions for date-only conversion as most do some sort of conversion to a timestamp, which risks a timezone conversion changing your date portion back a day if you are running in a timezone east of GMT.
For a few lines of Java, you may be better off implementing your own Function. If you are on a Java 8 (or higher) JVM, the new java.time.LocalDate and java.time.format.DateTimeFormatter classes are ideal for doing this conversion without involving times and timezones.
If you had:
(e.g. "d MMM yyyy", you may need "dd MMM yyyy" if the day portion is zero-padded when less than 10)
The Function would be something like:
I would expect the String value returned could be stored in a "Date only" property