[thelist] ASP.NET - Date Logic Question
Gary McPherson
lists at ingenyus.net
Thu Oct 7 09:11:05 CDT 2004
----Original Message----
From: thelist-bounces-lists=ingenyus.net at lists.evolt.org
[mailto:thelist-bounces-lists=ingenyus.net at lists.evolt.org]
On Behalf Of Casey Crookston
Sent: 07 October 2004 14:53
To: thelist at lists.evolt.org
Subject: [thelist] ASP.NET - Date Logic Question
> Need a little help with logic... what's the best way to
> display the date of the most recent Monday? In other words,
> no matter what day of the week it is, I need to say "Download
> the newsletter for the week of October 4th, 2004" Until next
> week, when it will change to "Download the newsletter for the week of
> October 11th, 2004"
>
> Is there a way to derive what day of the week it is as an
> integer? Monday = 2, Tuesday=3, etc?
>
> Thanks,
>
> Casey
Use DateTime.DayOfWeek to give you the number of the current day, then it's
easy to derive the date of the previous Monday from that by simple
subtraction, e.g. (C#):
DateTime dtToday = DateTime.Now;
DateTime dtMonday = dtToday.AddDays(1-dtToday.DayOfWeek);
Hope that helps,
Gary
More information about the thelist
mailing list