[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Date Difference

Subject: Re: Date Difference
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 19 Dec 2005 18:11:43 GMT
xslt2 date
> I basically have two strings :   "9/11/2004"  and "10/25/2005"
> and would like to produce the number of days between the two.

I didn't know there was a month 25.

> and would like to produce the number of days between the two.

that's not too hard really, you just extract the year month and date
components using substring-before and substring after and then calculate
the number of days in each case (ignoring leap years) then correct for
leap years by comparing y mod 4 - y mod 100 + y mod 400 in each case.
(or y-1 if the actual date is in jan or feb)

>   If that is too difficult it would be OK for me to know if one is equal to
>   the other ... or maybe if one is equal to, less than or greater than the
>   other.

exctract the three fields as above, format using format-number() so they
are two or four digits exactly then concatenate the fields as yyyymmdd
and compare the result as integers.

XSLT2 has date arithmetic built in but only if you have your dates in a
standard format such as 2005-10-25 so even with xslt2 you'd have to use
substring (or regexp-replace) originally to get your dates in a standard
form.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.