After try parsing the datetime out below, i want towrite logic that restrict the user to 45 days from current date or should I say if the datetime is in detween 45 days from the current date then do something else continue, so today is 03/26, 45 days from the 03/26 would be 02/09/12 or 02/08/12. so if datetime is between that range ( 03/26 would be 02/09/12) then i process data or else continue.
if (DateTime.TryParseExact(dateTimeConstruct, "yyyyMMdd HHmmss", null, 0, out dateTime))
{
if (dateTime.Day > 45)
{
}
}
Datetime rnage verification
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Mar 26, 2012, 2:46 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 26, 2012, 7:35 PM EDT
same thing u can achive by following code
string dateTimeConstruct = "20120326 000000";
DateTime dateTime;
if (DateTime.TryParseExact(dateTimeConstruct, "yyyyMMdd HHmmss", null, 0, out dateTime))
{
DateTime endDate = DateTime.Today;
var k = endDate.Subtract(dateTime).Days;
if (k <= 45)
{
// do something
}
else
{
// do something else
}
}
hope this help.