Convert DateTime to seconds

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxin
    New Member
    • Jan 2009
    • 13

    #1

    Convert DateTime to seconds

    Hi,

    I have some date time in xml file:
    Code:
    <?xml version="1.0"?>
    <ProductionPerformance>
    	<ActualStartTime>2008-12-07T01:00:00</ActualStartTime>
    	<ActualEndTime>2008-12-09T01:00:00</ActualEndTime>
    </ProductionPerformance>
    where I need to convert ActualStratTime to seconds in xsl:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    
    <xsl:stylesheet version="1.0" 
    	xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    	xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
    		
    	
    <xsl:include href="date/functions/date-time/date.msxsl.xsl"/>
    
    <xsl:template match="/ProductionPerformance">
    <item>
    	<xsl:variable name="mydatetime" select="'2009-02-27T15:34:01'"/>
    	<xsl:value-of select="date:seconds($mydatetime)"/>
    </item>
    <item>
    	<xsl:value-of select="./ActualStartTime"/>
    </item>
    <item>
    	<xsl:variable name="myseconds" select="./ActualStartTime"/>
    	<xsl:value-of select="date:seconds($myseconds)"/>
    </item>
    </xsl:template>
    </xsl:stylesheet>
    I use date:seconds function to convert the ActualStartTime . It works in the first item when I write '2009-02-27T15:34:01'´as input for the function. However, it does not works anymore when I try to get data from item ./ActualStartTime from the first xml file. I got an error: "Microsoft JScript runtime error Wrong number of arguments or invalid property assignment line = 953, col = 3 (line is offset...
    ". It seems that it can not get the input.

    Could someone help?
    Regards
    maxin
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Try
    Code:
    <xsl:variable name="myseconds">
      <xsl:value-of select="./ActualStartTime"/> 
    </xsl:variable>
    The difference? $myseconds is now a String instead of an XMLNodeList.

    Comment

    • maxin
      New Member
      • Jan 2009
      • 13

      #3
      Hi,
      Thanks for your answer. However, I get the same error as before.
      Regards
      maxin

      Comment

      Working...