Copied to clipboard

Flag this post as spam?

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


  • Martin Rud 232 posts 902 karma points c-trib
    Jun 24, 2020 @ 05:08
    Martin Rud
    0

    Trying to format date from Umbraco.DateTime property gives "No overload for method 'ToString' takes 1 arguments"

    I have the following code:

    timespan.Value("startTime").ToString("d. MMMM yyyy kl. HH.mm");
    

    Where timespan.Value("startTime") comes from an Umbraco.DateTime property.

    This gives me the error: "No overload for method 'ToString' takes 1 arguments".

    How can I format the date without errors?

  • Jan Hansen 20 posts 50 karma points
    Jun 24, 2020 @ 06:28
    Jan Hansen
    100

    Did you try casting, converting or specifying the DateTime?

    timespan.Value<DateTime>(...).ToString(...)
    
    ((DateTime)timespan.Value(...)).ToString(...)
    
    Convert.ToDateTime(timespan.Value(...)).ToString(...)
    
  • Martin Rud 232 posts 902 karma points c-trib
    Jun 24, 2020 @ 08:10
    Martin Rud
    0

    Cool - that works for me:

    var startTime = timespan.Value<DateTime>("startTime");
    var startTimeString = startTime.ToString("d. MMMM kl. HH.mm");
    
Please Sign in or register to post replies

Write your reply to:

Draft