?
Solved

compare date, if less than today

Posted on 2004-11-16
8
Medium Priority
?
6,341 Views
Last Modified: 2012-05-05
I want to turn on an indicator if this value is less than today's date.

DateTime.Parse(dr["birthday"].ToString())).ToString("MMM-dd-yyyy")

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?
0
Comment
Question by:lobos
5 Comments
 
LVL 15

Accepted Solution

by:
Timbo87 earned 100 total points
ID: 12598907
if(DateTime.Parse(dr["birthday"].ToString())).ToString("MMM-dd-yyyy") < DateTime.Now)
     // birthday is less than today's date
else
     // birthday is greater than today's date
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12599429
I think,

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

Might be a little closer...
0
 

Author Comment

by:lobos
ID: 12626691
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.
Thanks.
0
 

Expert Comment

by:isteffen
ID: 12643782
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
0
 
LVL 10

Assisted Solution

by:eternal_21
eternal_21 earned 100 total points
ID: 12737860
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)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 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