Copied to clipboard

Flag this post as spam?

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


  • Karl 5 posts 29 karma points
    May 13, 2010 @ 04:46
    Karl
    0

    umbraco.library:FormatDateTime($myDate, 'M') not working as expected

    Umbraco 4.0.2.1

    umbraco.library:FormatDateTime($myDate, 'M') 

    Should return single-digit month; 1 for January, 2 for February ... 12 for December.

    I get full month name followed by two-digit day (January 01, December 24).

  • Chris Dunn 210 posts 401 karma points
    May 13, 2010 @ 05:38
    Chris Dunn
    1

     Prefix a '%' before the 'M' format specifier for a single digit month alone.

    umbraco.library:FormatDateTime($myDate, '%M') 

    From microsoft:

    Note that if the 'M' format specifier is used alone, without other custom format strings, it is interpreted as the standard month day pattern format specifier. If the 'M' format specifier is passed with other custom format specifiers or the '%' character, it is interpreted as a custom format specifier.

    http://msdn.microsoft.com/en-us/library/8kb3ddd4(VS.71).aspx

    -Chris

  • Aaron Powell 1708 posts 3046 karma points c-trib
    May 13, 2010 @ 05:41
    Aaron Powell
    0

    That is expected behavior, that is how the .NET date formatter works. Refer to the MSDN docs for full details on formatting dates: http://msdn.microsoft.com/en-us/library/zdtaw1bw(v=VS.100).aspx

  • Karl 5 posts 29 karma points
    May 14, 2010 @ 05:18
    Karl
    0

    Great answer, Chris.  Putting the % in front of the 'M' worked perfectly.  This is on Microsoft, not Umbraco, but would it be prudent to also note this in our Wiki page?

    http://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime

  • Chris Dunn 210 posts 401 karma points
    May 14, 2010 @ 05:34
    Chris Dunn
    0

    Good idea.  It has been done.

    -Chris

Please Sign in or register to post replies

Write your reply to:

Draft