Click to See Complete Forum and Search --> : Get First Day of week


dewoul
February 26th, 2007, 09:57 AM
Hi all,
i want get the first day of the week from today date. How can i do this?
Thank's

laitinen
February 26th, 2007, 10:35 AM
Hi all,
i want get the first day of the week from today date. How can i do this?
Thank's

hi,

Do you mean how to get the first date of the current week?


System.DateTime today = System.DateTime.Now;

int dayOfWeek = (int)today.DayOfWeek;

System.DateTime firstDayOfWeek = today.Subtract(new TimeSpan(dayOfWeek, 0, 0, 0));


this assumes that sunday is first day of week. If you want to have monday as first day:


System.DateTime today = System.DateTime.Now;

int dayOfWeek = (int)today.DayOfWeek-1;

if (dayOfWeek ==-1)
dayOfWeek = 7;


System.DateTime firstDayOfWeek = today.Subtract(new TimeSpan(dayOfWeek, 0, 0, 0));

Regards,

Laitinen

Talikag
February 26th, 2007, 10:36 AM
The method DayOfWeek of DateTime object

DateTime current = DateTime.Now;
MessageBox.Show(current.DayOfWeek.ToString());

laitinen
February 26th, 2007, 11:12 AM
The method DayOfWeek of DateTime object

DateTime current = DateTime.Now;
MessageBox.Show(current.DayOfWeek.ToString());


This does not get the first day of week. See post #2.

Regards,

Laitinen