I am doing an activity monitor based on date which is similar to stackoverflow Today,YesterDay,this week,Last week,this month,last Month
..... Based on current date how to get start-date
and end-date
for all these Today,YesterDay,this week,Last week,this month,last Month
in c#?
views:
57answers:
1
+4
A:
DateTime baseDate = DateTime.Today;
var today = baseDate;
var yesterday = baseDate.AddDays(-1);
var thisWeekStart = baseDate.AddDays(-(int)baseDate.DayOfWeek);
var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1);
var lastWeekStart = thisWeekStart.AddDays(-7);
var lastWeekEnd = thisWeekStart.AddSeconds(-1);
var thisMonthStart = baseDate.AddDays(1 - baseDate.Day);
var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1);
var lastMonthStart = thisMonthStart.AddMonths(-1);
var lastMonthEnd = thisMonthStart.AddSeconds(-1);
Adam Robinson
2010-05-12 17:09:13
Man, I hate when people catch their own mistakes that quickly. :)
MusiGenesis
2010-05-12 17:14:50
@MusiGenesis: Haha, sorry about that! ;)
Adam Robinson
2010-05-12 17:16:45
@Adam worked pretty well...
chandru_cp
2010-05-12 17:24:07
@Adam plz help me out http://stackoverflow.com/questions/2821358/what-is-wrong-with-this-sql-statement
chandru_cp
2010-05-12 18:10:28