Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2011, 05:57 PM
Authorized User
 
Join Date: Sep 2008
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default manipulation of text in date format

How do I remove and re-arrange data DD-MM-YYYY to YYYYMMDD for example given 03-09-2011 how do I manipulate it to 20110903
 
Old March 8th, 2011, 08:23 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The code is tedious but simple, it just involves a call on concat() and several calls on substring()
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 6th, 2014, 04:54 AM
Authorized User
 
Join Date: Aug 2013
Posts: 30
Thanks: 9
Thanked 0 Times in 0 Posts
Default M/D/YYYY H:MM:SS

is it the same if I need to change from M/D/YYYY H:MM:SS to YYYY-MM-DD?

or should I first convert to MM/DD/YYYY HH:MM:SS?

<xsl:variable name="date" select="xs:date(concat(
substring($d,6,4),'-',
substring($d,1,2),'-',
substring($d,3,2)
))"/>
<xsl:value-of select="format-date($date,'[Y1,4]-[M2]-[D2]')"/>

with substring, unless I do not understand something it seems not possible to tell a regular start and length as both M and D might actually be 2 characters.

thanks for any help

Last edited by pietromaria.liuzzo; March 6th, 2014 at 05:03 AM..
 
Old March 6th, 2014, 05:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XPath 2.0 this is best done using regular expressions.

If you're stuck with 1.0, you can do it with a tedious sequence of calls on substring-before() and substring-after().
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 6th, 2014, 05:14 AM
Authorized User
 
Join Date: Aug 2013
Posts: 30
Thanks: 9
Thanked 0 Times in 0 Posts
Default

I would be very glad to do this with regex.

what I tried to do is to put in a variable only the date using (\d*)/(\d*)/(\d\d\d\d)
but I believe my regex is probably wrong, cause I get no result.

could you please help me?

thank you very much
Pietro
 
Old March 6th, 2014, 05:23 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First, a new question should go on a new thread. Don't hijack old threads from years ago.

Secondly, if your code is wrong then I can help you get it right, but only if you show me your code.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Time and Date Manipulation Stoibeaj C++ Programming 3 August 22nd, 2010 11:03 PM
Date Manipulation pallone Javascript How-To 2 May 5th, 2006 02:15 PM
HELP Needed in Date Manipulation kunjan SQL Language 9 March 19th, 2006 09:51 PM
Date manipulation otarboy Access 1 September 20th, 2004 11:50 AM
Text manipulation Thomas82 Classic ASP Databases 2 February 26th, 2004 04:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.