How to format time XSL 1.0

Posted on 2006-03-20
Last Modified: 2012-08-13
I'm trying to format this line to exclude the seconds at the end.

Any ideas?

<xsl:value-of select="TRANSACTION/PRINTTIME" />

I tried using format-time, then realized its not available in this version...
Question by:JonCardona
    LVL 12

    Accepted Solution

    The answer is probably dependent on the format of the time itself.

    One possibility which removes the last 2 characters
    <xsl:value-of select="substring(TRANSACTION/PRINTTIME), 1, string-length(TRANSACTION/PRINTTIME) - 2)"/>
    LVL 60

    Expert Comment

    by:Geert Bormans
    Date formatting in XSLT is always a matter of substring operations
    (unless you are using data-types in XSLT2.0)
    functions to check are

    substring(string, number, number)
    substring-before(string, string)
    substring-after(string, string)

    also handy are
    translate() and normalize-space()

    it is important for us to know how the date format is in order to help
    There is a fair chance that jkmyoungs solution works
    of course you need a -3 instead of -2 if the format has an 's' for seconds

    if your format is something like this
    it could be safer to have
    substring-after(substring-after(TRANSACTION/PRINTTIME, ':') , ':')
    because that also works with this
    12:24:5 instead of 12:24:05

    all depends on what you have,
    but you are into heavy substringing :)

    most XSLT programmers have over time built their own little date processing library,
    or use one of the many available "out there"

    one thing worth checking out is EXSLT,
    that is a standardised XSLT extension, that has some extra functionality,
    There is a date library, and you never know it is supported by your processor,
    just check it out


    Author Comment


    This worked perfectly. Thanks!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now