Solved

# compare date, if less than today

Posted on 2004-11-16
Medium Priority
6,341 Views
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
Question by:lobos

LVL 15

Accepted Solution

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

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

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

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

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

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