Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Mar 19, 2013 @ 19:33
    Daniel Larsen
    0

    Format date ToString error

     

    Hi, I have a frustrating error, when trying to format a date. I have tested different solutions, but no luck, so now i turn to you guys. I get this error:

    error CS1501: No overload for method 'ToString' takes 1 arguments

    In my eyes it looks right, but maybe I am missing something. The "empHire" is a Date Picker.

    @{
    var members = Member.GetAll;  
    foreach (var item in members) {

    ... var hire = item.getProperty("empHire").Value.ToString("d MMMM yyyy");

      <p>@hire</p>
    ...
    }
    }

    Thank you :-)

  • gary 385 posts 916 karma points
    Mar 19, 2013 @ 21:18
    gary
    0

    Hi Daniel

    Dates are as strange as images, sometimes.

    In u6.0.2 Mvc, I have, using your example;

    @item.EmpHire.ToString(f") which gives full date-time but also works with ("d MMMM yyyy") from a date-picker.

    However am using @CurrentPage as opposed to @Model.Content (think that does make a difference due to the ouput being XML, but not 100% sure)

     

    Hope it helps G

  • Daniel Larsen 116 posts 381 karma points
    Mar 19, 2013 @ 21:32
    Daniel Larsen
    0

    Thank you for the response, but it did not help unfortunatly. I am trying to get a date from a Member, not a page, but I don't know if this makes any difference. I can get it to display the full date and time, but I only need the date. 

    I have used the .ToString formatting before with luck, but not this time :-/

    Daniel

  • Daniel Larsen 116 posts 381 karma points
    Mar 21, 2013 @ 11:40
    Daniel Larsen
    102

    I got it working with this:

    var hire = item.getProperty("empHire").Value;
    hire = string.Format("{0:d MMMM yyyy}", @hire); 

     

    <p>@hire</p>

    :-)

  • Molly 94 posts 134 karma points
    Mar 21, 2013 @ 12:26
    Molly
    0

    I have a similar problem to this. I don't get an error, my razor saves with no errors using Daniel's method above.

    var time = SiteContext.Current.CatalogContext.CurrentProduct.DynamicProperty().CourseDate.Value;

    string.Format("{dddd MMMM d yyyy}", @time

    however the razor script won't load on the frontend. I've tried various different ways

    var time = SiteContext.Current.CatalogContext.CurrentProduct.DynamicProperty();

    @time.CourseDate

    Displays the date as 04/14/2013 in US form It is a UK site so i need it to display as e.g.

    Wednesday 4th April 2013

    When i try it as follows: 

    @time.CourseDate.Value.ToString("dddd MMMM d, YYYY")

    @time.CourseDate.Value.FormatDateTime("dddd MMMM d, YYYY")

    @time.CourseDate.Value.Format("dddd MMMM d, YYYY")

    it saves with no errors but doesn't display. 

    I've also tried GetProperty("CourseDate") in place of DynamicProperty() with no success.

    The CourseDate is using datepicker data type not the Date Time already built in.

    Any help would be appreciated. Thank You.

     

  • Amir Khan 1282 posts 2739 karma points
    Dec 02, 2013 @ 22:45
    Amir Khan
    0

    Is there a way to update this so it doesn't show the time?

Please Sign in or register to post replies

Write your reply to:

Draft