Copied to clipboard

Flag this post as spam?

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


  • Oliver 5 posts 45 karma points
    Nov 06, 2013 @ 09:18
    Oliver
    0

    Compare DateTime with Umbraco Date Picker

    I want to compare todays date with the picked date for a show to determine if it has passed or not.

    Here is my code:

    var currentDate = DateTime.Today;
    var postDateUnformatted = string.IsNullOrWhiteSpace(mediaItem.GetPropertyValue("contentYear")) ? mediaItem.CreateDate : mediaItem.GetPropertyValue("contentYear");

    @currentDate outputs = 2013-11-06 00:00:00

    @postDateUnformatted outputs = 2015-11-04T00:00:00 

    These outputs are unfortunately not something I can compare, how should I solve this?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 06, 2013 @ 09:30
    Dennis Aaen
    100

    Hi Oliver and welcome to Our,

    Maybe this post can help you in the right dirction I hope so

    http://our.umbraco.org/forum/developers/api-questions/21506-problem-parsing-datepicker-value-to-DateTime-with-API

    /Dennis

  • Oliver 5 posts 45 karma points
    Nov 06, 2013 @ 10:35
    Oliver
    0

    Thank you, it did help me!

    This is what I ended up with:

    var currentDate =DateTime.Today;
    var postDateUnformatted = string.IsNullOrWhiteSpace(mediaItem.GetPropertyValue("contentYear")) ? mediaItem.CreateDate : mediaItem.GetPropertyValue("contentYear");
    postDateUnformatted = System.Xml.XmlConvert.ToDateTime(postDateUnformatted);
    if (postDateUnformatted > currentDate)
    {
    //Upcoming shows
    }
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Nov 06, 2013 @ 10:41
    Jeavon Leopold
    0

    Hi Oliver,

    If you are using Mvc, then something like this?

    var currentDate = DateTime.Today;
    if (mediaItem.HasValue("pickedDate") && mediaItem.GetPropertyValue<DateTime>("pickedDate") < currentDate)
    {
        <p>Item pickedDate has passed</p>        
    }    
    

    If you are using a Razor Macro with DynamicNode, then something like this?

    var currentDate = DateTime.Today;
    if (mediaItem.HasValue("pickedDate") && mediaItem.GetPropertyValue("pickedDate").AsDateTime() < currentDate)
    {
        <p>Item pickedDate has passed</p>        
    }    
    

    Jeavon

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 06, 2013 @ 10:43
    Dennis Aaen
    0

    Hi Oliver.

    I´m glad to hear that and I´m happy that I could help you.

    I think that you should mark is question as solved so it helps others too. And they can see was worked for you. The way you mark a quesiton as solved is like this:

    When you got a right answer. Then find the person who have give you the solution or direction to solve your problem There you will see a green tick, hit this green tick and you have marked your question as solved.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft