Question
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-04/0aeea859-d28c-4613-ad9b-910b23846ea5.jpg?h=f9b91d5d&itok=P_fwua_A)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-04/0aeea859-d28c-4613-ad9b-910b23846ea5.jpg?h=f9b91d5d&itok=P_fwua_A)
Pegasystems Inc.
GB
Last activity: 29 Feb 2016 7:12 EST
How to map a string to date property in a data page
I am trying to map to a Date Time property in a data page from XML. In the XML the date time is string in a format like the below example:
2016-02-01 13:29:23 i.e. yyyy-MM-DD HH24:mm:ss
I am trying to map this in the data transform, but keep getting empty or incorrect dates e.g. I see 19700101T000000.000 GMT on the clipboard.
I have tried using @DateTime.parseDateString(.propertry) but this dosn't seem to support this format.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Updated: 2 Feb 2016 12:41 EST
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
Pegasystems Inc.
GB
The following Activity works - using Java Steps.
You might want to re-factor this into a Function (or two functions I guess) : or at least re-factor into a single Activity rather than the two I'm using here (one that using Params, the other using Pages - which calls the first one).
Additionally: I decided to split the Date and Time Components into a PRPC 'Date' Property and a PRPC 'TimeOfDay' Property - this is because these two types have simple well-defined internal-storage formats in the help:
See: (prpchost:port)://prhelp/procomhelpmain.htm#concepts/concepts2/conceptsdatetime.htm
The internal representations
The internal representation of a Date value is eight digits in the format YYYYMMDD, for example 20061215 for December 15, 2006.
The internal representation of Time of Day value is six digits in the format HHMMSS, where the hours portion ranges from 00 to 23. For example, 153025 represents 25 seconds after 3:15 P.M.
Additionally the PRPC help page:
(prpchost:port)://prhelp/procomhelpmain.htm#designer studio/expressionbuilder/ref_conversions.htm
Has a Table showing different 'casting' operations allowed in Pega7 : and for Text->Date, and Text->TimeOfDay; the casting operation is marked as 'C'.
Which means:
Copies the value without examining whether it is valid.
The following Activity works - using Java Steps.
You might want to re-factor this into a Function (or two functions I guess) : or at least re-factor into a single Activity rather than the two I'm using here (one that using Params, the other using Pages - which calls the first one).
Additionally: I decided to split the Date and Time Components into a PRPC 'Date' Property and a PRPC 'TimeOfDay' Property - this is because these two types have simple well-defined internal-storage formats in the help:
See: (prpchost:port)://prhelp/procomhelpmain.htm#concepts/concepts2/conceptsdatetime.htm
The internal representations
The internal representation of a Date value is eight digits in the format YYYYMMDD, for example 20061215 for December 15, 2006.
The internal representation of Time of Day value is six digits in the format HHMMSS, where the hours portion ranges from 00 to 23. For example, 153025 represents 25 seconds after 3:15 P.M.
Additionally the PRPC help page:
(prpchost:port)://prhelp/procomhelpmain.htm#designer studio/expressionbuilder/ref_conversions.htm
Has a Table showing different 'casting' operations allowed in Pega7 : and for Text->Date, and Text->TimeOfDay; the casting operation is marked as 'C'.
Which means:
Copies the value without examining whether it is valid.
So it's on us to make sure the Text Property being cast to Date/TimeOfDay is really what we need it to be.
I'm using the Joda Time Library : but this is already included in PRPC - so no need to import anything.
Joda Time has two simple types called 'LocalDate' and 'LocalTime' - which are conceptually the same as a PRPC 'Date' and a PRPC 'TimeOfDay' (They represent just a date and just a time only : no timezones to complicate things).
They also provide validation checks: including rejecting non-existant dates (2015-02-29 will fail [not a leap year], whereas 2016-02-29 is fine [is a leap year]) for instance).
Java Steps are shown below - First Date and then Time:
try { org.joda.time.LocalDate localdate=new org.joda.time.LocalDate(InDateString); outDateString=localdate.toString("YYYYMMdd"); } catch(Exception e) { throw new PRRuntimeException(e); }
[NOTE : See my REPLY below for a slight correction to this (the ':' shouldn't be here) - although this step apparently still worked as-is]
try { org.joda.time.LocalTime localtime=new org.joda.time.LocalTime(InTimeString); outTimeString = localtime.toString("HH:mm:ss"); } catch(Exception e) { throw new PRRuntimeException(e); }
I have switched on a JUMP step upon exception for both these steps - just jumps to the END of the Activity.
You might want to change this so that it 'dirties' the page rather than chuck an exception - dunno.
[But it's better that it flags the error when it happens rather than finding out later that the date is set to 1970-01-01 I think]
And here's my second testing Activity - which just calls the first: and sets Properties on a Page.
I have three Properties defined on my class here: 'MyInputString' , 'MyDateProp' and 'MyTimeProp'.
They are 'Text', 'Date' and 'TimeOfDay' respectively.
Here's my Page after running it:
<pagedata> <MyInputString>2016-02-02 13:29:23</MyInputString> <MyTimeProp>132923</MyTimeProp> <pxObjClass>Tmp-scratch-Work</pxObjClass> <MyDateProp>20160202</MyDateProp> <pzStatus>valid</pzStatus> </pagedata
The Activity is essentially hardcoded to only accept dates exactly in the format you have (an ISO-8601 format I believe).
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
![](https://accounts.pega.com/sites/default/files/pega-user-image/35/REG-34624.png?source=PUMINIT)
Pegasystems Inc.
GB
NOTE: I actually had overly formatted the timestring (although it still appeared to have worked...) in the second Java Step.
The 'internal represenation' for the 'TimeOfDay' type has no separators; so the step should be in fact this:
try { org.joda.time.LocalTime localtime=new org.joda.time.LocalTime(InTimeString); outTimeString = localtime.toString("HHmmss"); } catch(Exception e) { throw new PRRuntimeException(e); }
(Whereas it was 'HH:mm:ss')
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-08/ef69651d-5c2a-46e8-aee2-6ad474f73db6.png?h=b6be84b4&itok=Cx2phisk)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/2024-08/ef69651d-5c2a-46e8-aee2-6ad474f73db6.png?h=b6be84b4&itok=Cx2phisk)
GovCIO
US
Hi John,
Very good info provided on the formatting of date using "Joda" standards. What extra formatting features we can get from this standard? I hope this comes as a part of V7.1.6 and above. Please let me know.
Thanks,
Ravi Kumar.
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Cognizant Technology Solutions
IN
Hi John,
This is really very helpful piece of information. We have been facing such date type formatting and casting issues as well in our project.
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/1689960000/ae8790be-3188-41aa-8de4-bc39bb0600a4.jpg?itok=9hY_zG3Q)
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/1689960000/ae8790be-3188-41aa-8de4-bc39bb0600a4.jpg?itok=9hY_zG3Q)
Pegasystems Inc.
IT
Brilliant step by step guide John!
As a side note Java 8 brings the new java.time API, originally started as JSR-310, and led by the author of Joda-Time.
The new API was "inspired by Joda-Time" according to the project leader which recommends to migrate to java.time from Java SE 8 onward.
According to the Pega Platform Support Guide Java 8 SE is supported from Pega 7.1.8 onward so the new API could be available with Tomcat 8 and JBoss EAP 6.4.
Following there is a post from the Joda-Time author that explains how to migrate to the new API.
Stephen Colebourne's blog: Converting from Joda-Time to java.time
Both Joda-Time classes used in your example have the same counterpart in the java.time API.