Questions tagged [dayofweek]

Usually a function that returns day of the week when a certain date object is passed.

Get day of day of the week in:

691 questions
23
votes
2 answers

.OrderBy(DayOfWeek) to treat Sunday as the end of the week

I'm ordering a number of objects by their System.DayOfWeek property. DayOfWeek treats Sunday as the start of the week, whereas I would like it to be ordered so it appears at the end. It's just an enum, so I can't modify it. However I've read that I…
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
23
votes
5 answers

Check if DAY_OF_WEEK is between Monday and Friday

I'm trying to create a method which is checking if "today" is between Monday and Friday. For this I get with this line 'int day = Calendar.DAY_OF_WEEK;' the actual day. After that I fill a ArrayList with the days (Monday, Tuesday, Wendsday,…
safari
  • 7,565
  • 18
  • 56
  • 82
22
votes
1 answer

DateTime.DayOfWeek micro optimization

First of all: I'm asking this question just for fun and eager to learn. I have to admit I love to mess around with micro-optimizations (Although they have never led to any significant increase in speed in any of my developments). The…
rpax
  • 4,468
  • 7
  • 33
  • 57
21
votes
8 answers

How to get first day of a given week number in Java

Let me explain myself. By knowing the week number and the year of a date: Date curr = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(curr); int nweek = cal.WEEK_OF_YEAR; int year = cal.YEAR; But now I don't know how to get the date…
framara
  • 2,833
  • 5
  • 28
  • 32
21
votes
2 answers

How to add number of days to a date, consider only business days (i.e. ignore weekends)?

I'm trying to create a formula to calculate the n-th Business Date (only Monday to Friday are business days). For simplicity's sake, holidays are not important; only weekends should be ignored. For example: …
E.Z.
  • 6,393
  • 11
  • 42
  • 69
20
votes
11 answers

Get last Friday's Date unless today is Friday using T-SQL

I'm trying to get the correct SQL code to obtain last Friday's date. A few days ago, I thought I had my code correct. But just noticed that it's getting last week's Friday date, not the last Friday. The day I'm writing this question is Saturday,…
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
19
votes
6 answers

For each loop through DayOfWeek enum to start on Monday?

I am iterating through the DayOfWeek Enum like this : foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek))) { // Add stuff to a list } And my problem is that I would like my enum to start by Monday instead of Sunday. I tried to do :…
Oliver
  • 807
  • 2
  • 12
  • 23
18
votes
3 answers

C#: Set initial DayOfWeek as Monday not Sunday

Is there a way to set the first DayOfWeek as Monday = 0 not Sunday? (int)dateList[0].DayOfWeek == 0) // 0 = Sunday
msfanboy
  • 5,273
  • 13
  • 69
  • 120
18
votes
4 answers

How to set monday as first day of week in SQL Server

I am running SQL Server 2008 on a machine with regional settings that have Monday as the first day of the week. If I create a computed column in a table to compute the day of week for a date field then I get 2 for a Monday date instead of 1. Is…
Clipper87
  • 211
  • 1
  • 4
  • 7
17
votes
12 answers

Order by day_of_week in MySQL

How can I order the mysql result by varchar column that contains day of week name? Note that MONDAY should goes first, not SUNDAY.
Bogdan Gusiev
  • 8,027
  • 16
  • 61
  • 81
15
votes
4 answers

How can I get the 4 Mondays of a month with js?

I'm building a chart where the x-axis should be the four weeks of a month. I would like to display only the four Mondays of that month. I already have the currentMonth and the currentYear variables, and I know how to get the first day of the month.…
Gaelle
  • 614
  • 1
  • 7
  • 30
15
votes
10 answers

Get day from DateTime using C#

Silly question. Given a date in a datetime and I know it's tuesday for instance how do i know its tue=2 and mon=1 etc... Thanks
user9969
  • 15,632
  • 39
  • 107
  • 175
15
votes
4 answers

Num day to Name day with Pandas

If I use this funtion pd.DatetimeIndex(dfTrain['datetime']).weekday I get number of the day, but I don't find any function which give the name of de day... So I need to convert 0 to Monday, 1 to Tuestday and so on. Here is an example of my…
Yari
  • 867
  • 3
  • 9
  • 13
14
votes
2 answers

DateTimeFormatter weekday seems off by one

I'm porting an existing application from Joda-Time to Java 8 java.time. I ran into a problem where parsing a date/time string that contains a 'day of week' value triggered an exception in my unit tests. When parsing: 2016-12-21 20:50:25 Wednesday…
Niels Basjes
  • 10,424
  • 9
  • 50
  • 66
14
votes
1 answer

53rd week of the year in R?

I have week-date data in the form yyyy-ww where wwis the week number in two digits. The data span 2007-01 to 2010-30. The week counting convention is ISO 8601, which as you can see here on Wikipedia's "Week number" article, occasionally reaches 53…
dynamo
  • 2,988
  • 5
  • 27
  • 35
1
2
3
45 46