Page 1 of 1
How do I convert a string variable date into a date?
Posted: Thu Jun 26, 2014 9:34 pm
by winkimjr2
I have a xslt which is using a xml document. The xml document has a variable dateServed="06/20/2014". When I run the xslt, I get error FORG0001: Cannot conver xs:string with value '06/20/2014' to xs:date.
What do I need to do to convert this dateServed="06/20/2014" to a date?
Re: How do I convert a string variable date into a date?
Posted: Thu Jun 26, 2014 9:50 pm
by adrian
Hi,
xs:date expects the date to be in format yyyy-mm-dd, so you just have to adjust it to that format with the help of string functions.
There is an example showing this on stack overflow:
http://stackoverflow.com/questions/1685 ... n-xslt-2-0
Regards,
Adrian
Re: How do I convert a string variable date into a date?
Posted: Thu Jun 26, 2014 11:51 pm
by winkimjr2
I am still confused as to how to do this.
I have the following from xsl
Code: Select all
<NotificationEvent dateServed="06/20/2014"</NotificationEvent>
So how do I convert this date string to date?
Re: How do I convert a string variable date into a date?
Posted: Fri Jun 27, 2014 11:54 am
by adrian
For creating an xs:date (yyyy-mm-dd) from
dateServed='mm/dd/yyyy':
Code: Select all
<xsl:variable name="date" select="xs:date(concat(
substring(@dateServed,7,4),'-',
substring(@dateServed,1,2),'-',
substring(@dateServed,4,2)))"/>