473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Day Of Week

..NET enumerates the day of the week as 0-6 ( Sunday to Saturday ). This
seems to remain the same regardless of the culture settings.

Just wondering if this is alterable is some way, and if not how you guys
work out for example, next Sunday. I mean sure, I can create a function
which will allways return the number of days between today and sunday using
for example the day name and a select statement, but it seems too complex.

Any ideas on the simple approach ?
Mar 16 '08 #1
3 1522
Dont know if its the best way, but I solved it like this,

public static DateTime thisSunday(DateTime targetDate)

{

int realDay = 1;

if (targetDate.DayOfWeek == 0) realDay = 7; else realDay =
(int)targetDate.DayOfWeek;

return targetDate.AddDays(7 - realDay);

}

"Just Me" <news.microsoft.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
.NET enumerates the day of the week as 0-6 ( Sunday to Saturday ). This
seems to remain the same regardless of the culture settings.

Just wondering if this is alterable is some way, and if not how you guys
work out for example, next Sunday. I mean sure, I can create a function
which will allways return the number of days between today and sunday
using for example the day name and a select statement, but it seems too
complex.

Any ideas on the simple approach ?

Mar 16 '08 #2
Hi

The problem is not that the enumeration is 0 - 6. The complication
arises because you apparently require a logically different result for
Sunday than for other days of the week.

According to your solution if targetDate is Monday to Saturday then
you want to return the date for the *next* Sunday whereas if
targetDate is Sunday then you want to return the date unaltered i.e.
*this* Sunday.

For example if the code were written thus:

DateTime NextSunday(DateTime targetDate)
{
int dow = (int)targetDate.DayOfWeek;
return targetDate.AddDays(7 - dow);
}

the result would be the same as your solution except when targetDate
is Sunday, in which case you get next Sunday i.e. a week later.
Mar 16 '08 #3
Correct !

Thanks for your input.
"Stan" <go****@philphall.me.ukwrote in message
news:6f**********************************@e10g2000 prf.googlegroups.com...
Hi

The problem is not that the enumeration is 0 - 6. The complication
arises because you apparently require a logically different result for
Sunday than for other days of the week.

According to your solution if targetDate is Monday to Saturday then
you want to return the date for the *next* Sunday whereas if
targetDate is Sunday then you want to return the date unaltered i.e.
*this* Sunday.

For example if the code were written thus:

DateTime NextSunday(DateTime targetDate)
{
int dow = (int)targetDate.DayOfWeek;
return targetDate.AddDays(7 - dow);
}

the result would be the same as your solution except when targetDate
is Sunday, in which case you get next Sunday i.e. a week later.

Mar 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
21
by: .:mmac:. | last post by:
I have to update a page every week. I get the page ahead of time so I used the "scheduled includes" webbot in Frontpage only to find that I would have to refresh the page every week to have it...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
3
by: Steph. | last post by:
Hi, When I use the "Calendar.GetWeekOfYear" function (with "fr-BE" as CultureInfo and Monday as the first day of week) I get : Friday 31/12/2004 : week = 53
3
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the...
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.