I have a date that is in a format called \'String(Generalized-Time)\', see MSDN linked here , I need to check if this date is today and if it is do X.
To complicate thi
Like this:
DateTime dt;
if (DateTime.TryParse(stringValue, out dt) &&
dt.Date == DateTime.Today)
{
// do some stuff
}
To check if it's anytime within the last four days,
DateTime dt;
if (DateTime.TryParse(stringValue, out dt) &&
dt.Date > DateTime.Today.AddDays(-4f) &&
dt < DateTime.Now)
{
// do some stuff
}
or, as an extension method
public static bool WithinPreviousPeriod(this DateTime dt, int daysBack)
{
return dt.Date > DateTime.Today.AddDays(-daysBack))
&& dt < DateTime.Now;
}