SourceForge has been redesigned. Learn more.

date or datetime to date

  • Anonymous

    Anonymous - 2011-11-16

    Hello all,
    Is there a function that can take either a date or datetime and in both cases
    extract the date?

    So for 1956-01-03T00:00:00.0000000+02:00 it would give 1956-01-03 and same
    output for 1956-01-03.

    I am needing this because although I am expecting a date, I might receive a
    datetime from some external systems because of their own constraints.


  • Michael Kay

    Michael Kay - 2011-11-16

    I think you need to do something like this

    if ($x castable as xs:dateTime) then xs:date(xs:dateTime($x)) else xs:date($x)

    This question isn't Saxon-specific; a better place for general XSLT an XPath
    questions is the xsl-list at, or StackOverflow.

  • David Lee

    David Lee - 2011-11-16

    I have learned to use a horrible hack, assuming $x is a string ...

    xs:dateTime( fn:replace( $x , "T.*:,"") )


Log in to post a comment.