Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find specific date in the current week

Tags:

c#

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

like image 508
Mike Avatar asked Jul 09 '10 19:07

Mike


People also ask

How do I get the current day of the week in Javascript?

getDay() The getDay() method returns the day of the week for the specified date according to local time, where 0 represents Sunday.

How do you get current week in typescript?

Add the number of days to the current weekday using getDay() and divide it by 7. We will get the current week's number.

How do you get the current week start date and end date in typescript?

var today = new Date(); var startDay = 0; var weekStart = new Date(today. getDate() - (7 + today. getDay() - startDay) % 7); var weekEnd = new Date(today.


1 Answers

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);
like image 134
LBushkin Avatar answered Nov 06 '22 23:11

LBushkin