c# - Given the DayOfWeek number, find the date of a day in the previous week -
It's likely to be embarrassing simple, but I can not do a "basic math" type day. / P>
I have a system where we cut off orders based on that day, the way it is the day, for example, after Friday 4 o'clock you can not order for the next Sunday , Or after 2 o'clock, you can not order the next day. I know that I have to say that I need a product on Sunday, May 4, cutoff, and let me know that Friday is May 2.
So I have the following code that is not working correctly
int offset = (int) record. Diaf Wake - This Cafaded. Day_Number; Date time cutoffdate = racket Adid (Offset);
Where reqDate.DayOfWeek is Sunday (0) and it is cafeday.day_number Friday (5). I want Friday's date cutoff document value is true if the cutoff is the next day, but Sunday (DayOfWeek 0) seems to mess about everyone I often find that the right day should get, but next week, not last (I think we feel due to offset).
If anyone has a simple method, I would be very grateful for the help of getting past date of last arbitrary day in last one last week.
I also
((7- (int. ReqDate.DayOfWeek + thiscafeday.day_number)% 7)
But this Can not even get to work.
Any help appreciated.
You can use these extension methods:
public Fixed class date extension {public static date time next (date of this date, day of day off) {int start = (int) Diap wake; Int desired = (int) day off wake; If (wanted & lt; = start) + = 7 wanted; return from. Adidies (Like - Start); } Public static date time preceding (time of this date, Day of the day off) {int end = (int) Diap wake; Int desired = (int) day off wake; If (should> = end) end + = 7; return from. Adidies (desired - end); }} Last last Friday = DateTime.Today.Previous (DayOfWeek.Friday);
(This may require some customization for your specific scenario)
Comments
Post a Comment