472,373 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Calculate first and last date of a week

Hi:
Are there any algorithms I can use, that based on a given date and a
culture code (different cultures may have different beginning of week), I
can get first and last date of the current week?

Thanks!

--

WWW: http://hardywang.1accesshost.com
ICQ: 3359839
yours Hardy
Nov 15 '05 #1
5 40460
using System.Globalization;
using System.Threading;

CultureInfo info = Thread.CurrentThread.CurrentCulture;
DayOfWeek firstday = info.DateTimeFormat.FirstDayOfWeek;
DayOfWeek today = info.Calendar.GetDayOfWeek(DateTime.Now);

int diff = today - firstday;
DateTime firstDate = DateTime.Now.AddDays(-diff);
MessageBox.Show(firstDate.ToShortDateString());

Sadly, this does not work. DayOfWeek does not follow international
standards and will put Sunday as the first day independent of culture.

Try using (this assumes if not sunday, it has to be monday)
int diff = 0;
if(firstday != DayOfWeek.Sunday)
if(today == DayOfWeek.Sunday)
diff = 6;
else
diff = today - firstday;

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opryevibn6hntkfz@localhost...
Sadly, this does not work. DayOfWeek does not follow international
standards and will put Sunday as the first day independent of culture.


So where is Sunday not the first day of the week? Four thousand years of
tradition aren't good enough?
Nov 15 '05 #3
In European contries Monday is the first day of the week.
God worked 6 days and rested on the last day of the week (Sunday).
At least accourding to the (Christian) Bible.

In Israel Sunday is the first (working) day since Sabbat is from Friday
Sundown to Saterday Sundown.
The same for the Islamic world.

Just as most of the World sort it's Dates (DD.MM.YYY or YYYY.MM.TT) only 2
Cultures support an unsorted Date-Format (MM.TT.YYY) - they are US-English
and Swaili.

The DateTimePicker for NET.Framework (PC) supports the first day of weeks
for culture but not the samle DateTimePicker.cs that the offered for the
NET.Framework.Compact. I had work out these conditions to get it to work for
all supported languages.

BTW it is new to me that the US is 4000 years old

Mark Johnson, Berlin Germany
mj*****@mj10777.de

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
schrieb im Newsbeitrag news:eJ*************@TK2MSFTNGP10.phx.gbl...

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opryevibn6hntkfz@localhost...
Sadly, this does not work. DayOfWeek does not follow international
standards and will put Sunday as the first day independent of culture.


So where is Sunday not the first day of the week? Four thousand years of
tradition aren't good enough?

Nov 15 '05 #4
Mark Johnson <mj*****@mj10777.de> wrote:
In European contries Monday is the first day of the week.
God worked 6 days and rested on the last day of the week (Sunday).
At least accourding to the (Christian) Bible.


No, in Christian circles Sunday is the first day of the week. God
rested on the Sabbath, Saturday. I can't remember exactly when the
"rest day" moved from Saturday to Sunday for Christians, but Sunday is
most definitely the start of a Christian week in the UK at least.

Monday is the start of a business week just because that's more
convenient, I suspect.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
This is no doubt the reason why the Jews/Arabs "rest" on Saturday.
Be it as it may why the Christian "rest" on Sunday and not on Sunday - the
official
first day of the week here is Monday (as shown on the Calendars) so it must
be supported
when supporting Internationalsation.
I built the DateTimePicker to support all days of the week as the first day
so everyone should be happy.
Of cource if Mars has 8 or 10 days the week I am sunk - but i can live with
that at the moment

Mark Johnson, Berlin Germany
mj*****@mj10777.de

"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb im Newsbeitrag
news:MP************************@msnews.microsoft.c om...
Mark Johnson <mj*****@mj10777.de> wrote:
In European contries Monday is the first day of the week.
God worked 6 days and rested on the last day of the week (Sunday).
At least accourding to the (Christian) Bible.


No, in Christian circles Sunday is the first day of the week. God
rested on the Sabbath, Saturday. I can't remember exactly when the
"rest day" moved from Saturday to Sunday for Christians, but Sunday is
most definitely the start of a Christian week in the UK at least.

Monday is the start of a business week just because that's more
convenient, I suspect.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6

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

Similar topics

2
by: Targa | last post by:
Need to print "Week of (first day of week)" First day being Monday. ie: week = Request.querystring("mydate") response.write "Week of" & week If week = 5/6/2004 (which is Thursday) it should...
1
by: simon | last post by:
If I use day function: day(date), I get 1 for sunday. How can I set, that the first day of week is monday? Thank you for your answer, Simon
4
by: Morten Wennevik | last post by:
In an earlier thread I said first day of week was defined as monday, not sunday and forgot all about the thread, so I never got to reply on where it says that. So here it is. ISO 8601 -...
1
by: Martin Emanuelsson | last post by:
Hello, Knowing year and weeknumber of this year, I'm looking for some way to get the date of the first and last day of that particular week. Does anyone have an idea about how to do this? ...
2
by: Benz | last post by:
Hello all, Can anyone please tell me how to find the first and last date of a week when the year and the week number is given? The week model followed is the ISO model: Monday is the 1st day of...
0
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer)...
6
by: rohayre | last post by:
Im a long time java developer and actually have never done anything with java scripting. I'd like to write a short simple script for calculating a date in the future based on today's date and a...
9
by: ice | last post by:
Hello, I have a couple of tables. The client tables and the contacted tables. I am not sure how to start on this, what I need is a way to query all my clients then show any client that the...
3
reginaldmerritt
by: reginaldmerritt | last post by:
Hello I'm have a form displaying records from a table holding details of events. I'm using DFirst and DLast to work out what is the First and Last date. I have the following code which...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.