
Originally Posted by
dewoul
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?
Code:
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:
Code:
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