compare date, if less than today

Posted on 2004-11-16
Last Modified: 2012-05-05
I want to turn on an indicator if this value is less than today's date.


I want to turn on an indicator if this is less than today's day.
How can I do an if statement against the current date?
Question by:lobos
    LVL 15

    Accepted Solution

    if(DateTime.Parse(dr["birthday"].ToString())).ToString("MMM-dd-yyyy") < DateTime.Now)
         // birthday is less than today's date
         // birthday is greater than today's date
    LVL 10

    Expert Comment

    I think,

      if(DateTime.Parse(dr["birthday"].ToString()) < DateTime.Today)
        // birthday is less than today's date
        // birthday is greater than today's date

    Might be a little closer...

    Author Comment

    Ok can this be update the if statement a bit more I need to know if the date entered is equal to Nov.16,2004 then flag it.
    I am really bad with the syntact stuff.

    Expert Comment

    DateTime birthday = DateTime.Parse(dr["birthday"].ToString())).ToString("MMM-dd-yyyy");
    DateTime today = DateTime.Parse(DateTime.Now.ToShortDateString());

    if (birthday.CompareTo(today)<0)
         // birthday is less than today's date

    if (birthday.CompareTo(new DateTime(2004, 11, 16)) == 0)
        // birthday is equal to Nov.16th
    LVL 10

    Assisted Solution

    Assuming the field, "birthday" is of type DateTime, the following will yeild true when the date is Nov 16, 2004

      ((DateTime)dr["birthday"]).Date==new DateTime(2004, 11, 16)

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now