How would I be able to get the date of the Thursday in the current week? For example, Thursday of this current week is 7/8/2010
getDay() The getDay() method returns the day of the week for the specified date according to local time, where 0 represents Sunday.
Add the number of days to the current weekday using getDay() and divide it by 7. We will get the current week's number.
var today = new Date(); var startDay = 0; var weekStart = new Date(today. getDate() - (7 + today. getDay() - startDay) % 7); var weekEnd = new Date(today.
You can do this (alebit awkwardly) with the existing .NET DateTime. The trick is to use the DayOfWeek
enum as an integer - since it denotes the days Sun - Sat in ascending numeric order (0-6).
DateTime someDay = DateTime.Today;
var daysTillThursday = (int)someDay.DayOfWeek - (int)DayOfWeek.Thursday;
var thursday = someDay.AddDays( daysTillThursday );
Or even more simply:
var today = DateTime.Today;
var thursday = today.AddDays(-(int)today.DayOfWeek).AddDays(4);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With