Copied to clipboard

Flag this post as spam?

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


  • Natasha 79 posts 195 karma points
    Feb 05, 2016 @ 01:22
    Natasha
    0

    date time picker

    Hello

    In my Umbraco 6.1.6 page I have a field which is a date picker. I am referencing it in the code behind file as follows:

    item.GetProperty("propertyAlias").Value.ToString(); 
    

    How do I format this? At the moment the output is 2016.11.07T00:00:00 I would like it to be 11.07.2016

    Thank you Natasha

  • Daniel 60 posts 174 karma points
    Feb 05, 2016 @ 01:35
    Daniel
    1

    Haven't used this for a while, I think you can do:

    var dateTimeString = item.GetProperty("propertyAlias").Value.ToString();  //is Value already a String? not sure
    var dateTime = XmlConvert.ToDateTime(dateTimeString);
    var formattedDateTimeString = dateTime.ToString("dd.MM.yyyy");
    @formattedDateTimeString
    
  • Natasha 79 posts 195 karma points
    Feb 05, 2016 @ 11:33
    Natasha
    2

    Thanks so much Daniel

    With one minor change (in case anyone else needs it)

    var dateTime = System.Xml.XmlConvert.ToDateTime(dateTimeString);
    
Please Sign in or register to post replies

Write your reply to:

Draft