on 02-17-2009 6:45 PM
Hi,
I need to map a ENDDA field to a new field but subtracting a day, and reformatting the date, e.g
from:
<ENDDA>20090213</ENDDA>
I need:
<ENDDA>12.02.2009</ENDDA>
For reformatting, sub string and concat with . is working, but how can I substract a day, including the handling where the date is the first day of the month?
thx for your inputs
Hi
XSLT is not very promising on things like this
you can check this link which may be helpful
http://www.ibm.com/developerworks/library/x-exslt.html
Other Option
normally, you can use simple Java classes to achieve such things
1) specifiy the Java class in your namespace
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mygetDatefunction="com.xyz.abc.xi.general.getDate">
2) create a variable in xsl & call the methods within the Java class
<xsl:variable name="varCurrentDate" select="mygetDatefunction:getDateMethod1()"/>
3) then you can use the variable in your mapping
Regards
Vishnu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Here is the solution I finally used:
In the headers:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:Date="java:java.util.Date" exclude-result-prefixes="Date" >
and where I needed:
<!--Substracting 1900 year as counting from Jan 01 1900, 1 month as counting months from 0 to 11 and 1 day as we need the day before-->
<xsl:variable name="date" select="Date:new(substring(BEGDA,1,4)-1900,substring(BEGDA,5,2)-1,substring(BEGDA,7,2)-1)"/>
<xsl:variable name="day" select="Date:getDate($date)"/>
<xsl:variable name="month" select="1+Date:getMonth($date)"/>
<xsl:variable name="year" select="1900+Date:getYear($date)"/>
<xsl:if test="$day < 10">0</xsl:if><xsl:value-of select="$day"/>.<xsl:if test="$month < 10">0</xsl:if><xsl:value-of select="$month"/>.<xsl:value-of select="$year"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think this will help you.
Create one UDF and insert 2 parameters.
First parameter as your date
second is number of hours 24:00:00
Code:
//write your code here
SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
SimpleDateFormat sdTarget = new SimpleDateFormat("MM/dd/yyyy");
try {
Date currentDate = sd.parse(a);
Date compareDate = sd.parse(a.substring(0,10) + " " + b);
if (currentDate.after(compareDate) )
{
Calendar c = Calendar.getInstance();
c.setTime(sdTarget.parse(a));
c.add(Calendar.DATE,1);
a = sdTarget.format(c.getTime());
}
else
{
//a = "before"
a = a.substring(0,10) ;
}
}
catch(Exception e)
{
}
return a;
This might need little modification as your need.
After that use Date Transformation function which will convert date in your required format.
Thanks,
Hetal
Edited by: hetal shah on Feb 17, 2009 9:43 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.