Mike P wrote:
How would I check a datetime variable is within the last 7 days?
*** Sent via Developersdex http://www.developersdex.com ***
DateTime dt = ...; // the one you want to check
if (dt >= DateTime.Now.Ad dDays(-7))
{
}
this will rewind the clock 7 days back and check if "dt" is that point
in time, or after it.
However, if the current time of day is mid-day (12:00), and you want the
dt to be in the last 7 "days", where you include the whole day, then you
need to first get a DateTime value within that day 7 days back, and then
rewind the time to midnight.
DateTime dt7 = DateTime.Now.Ad dDays(-7);
dt7 = new DateTime(dt7.Ye ar, dt7.Month, dt7.Day, 0, 0, 0);
if (dt >= dt7)
{
}
--
Lasse Vågsæther Karlsen
mailto:la***@vk arlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3