Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • cchehn 28 posts 69 karma points
    Jun 06, 2013 @ 20:15
    cchehn
    0

    Formating Date picker with time using umbraco.library:FormatDateTime in xslt

    I am trying to split up a date time value into its various components so I can pass them into a jquery plugin from an xslt macro. This is on 4.11.4

    The Date Picker with time stores a value in (i think Xml time?)  Example: 2013-06-06T13:25:00

    I am trying to create a variable to hold each piece of the date with the following code:

     

    <!-- get the value from Date Picker with time -->
    <xsl:variable name="eventDateTime" select="$currentPage/eventDateTime" />
    <!-- Split it up into the parts needed --> 
    <xsl:variable name="eventYear" select="umbraco.library:FormatDateTime($eventDateTime,'yyyy')"/>
    <xsl:variable name="eventMonth" select="umbraco.library:FormatDateTime($eventDateTime,'M')"/>
    <xsl:variable name="eventDay" select="umbraco.library:FormatDateTime($eventDateTime,'d')"/>
    <xsl:variable name="eventHour" select="umbraco.library:FormatDateTime($eventDateTime,'H')"/>
    <xsl:variable name="eventMinute" select="umbraco.library:FormatDateTime($eventDateTime,'m')"/>

     

    But this generates an error:

    System.Xml.Xsl.XslTransformException: An error occurred during a call to extension function 'FormatDateTime'. See InnerException for a complete description of the error. ---> System.FormatException: Input string was not in a correct format. at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi) at System.DateTimeFormat.ExpandPredefinedFormat(String format, DateTime& dateTime, DateTimeFormatInfo& dtfi, TimeSpan& offset) at System.DateTimeFormat.Format(DateTime dateTime, String format, DateTimeFormatInfo dtfi, TimeSpan offset) at umbraco.library.FormatDateTime(String Date, String Format) --- End of inner exception stack trace --- at System.Xml.Xsl.Runtime.XmlExtensionFunction.Invoke(Object extObj, Object[] args) at System.Xml.Xsl.Runtime.XmlQueryContext.InvokeXsltLateBoundFunction(String name, String namespaceUri, IList`1[] args) at eventHour(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results) at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.presentation.umbraco.developer.Xslt.xsltVisualize.visualizeDo_Click(Object sender, EventArgs e)

    What format is expected here? I was going by the information in this wiki article: http://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime

    Thanks in advance,
    -C.

  • cchehn 28 posts 69 karma points
    Jun 06, 2013 @ 20:31
    cchehn
    0

    FYI it was the format.  I am going to try and update the wiki article.

    %M = 1 or 2 digit day
    %d = 1 or 2 digit day
    %H = 24 hour time
    %m = 1 or 2 digit time
  • Peter Grillo Frederiksen 34 posts 67 karma points
    Jul 15, 2013 @ 18:47
    Peter Grillo Frederiksen
    0

    As I see it, your problem lies here:
    name="eventDateTime"select="$currentPage/eventDateTime"/>

    You need something like:

    name="eventDateTime"select="$currentPage/data [@alias='eventDateTime']"/> 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies