473,405 Members | 2,167 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,405 software developers and data experts.

Day Of Week Totally %^#T$ up


Hi,

I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(numbers[2] -
1900,numbers[0],numbers[1]-1))).getUTCDay();

Date comes in as MM/DD/YYYY

This works fine, as long as I am looking in the same month within a 3
week period. But choose March 1st (Saturday) or any other day in
another month, and the day number is wrong.

6 hours I've been at this....any help would be greatly appreciated. I
just need the day number of the week.

Thank you,

John

Mar 24 '08 #1
3 1417
mt**@mtekusa.com wrote:
I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(numbers[2] -
1900,numbers[0],numbers[1]-1))).getUTCDay();

Date comes in as MM/DD/YYYY

This works fine, as long as I am looking in the same month within a 3
week period. But choose March 1st (Saturday) or any other day in
another month, and the day number is wrong.
You are doing two nonsensical subtractions, and you have mixed up the
arguments. First, there is no need and it does not make sense to subtract
1900 from the year value. Second, the second argument of Date.UTC() is the
month value; you have to subtract 1 *there*, and _not_ from the value for
the third argument (which is the day-of-month).

Otherwise on 2008-03-01 CE ("3/1/2008") you would end up with

var daynum = (new Date(Date.UTC(108, 3, 0)).getUTCDay();

The string representation of `new Date(Date.UTC(108, 3, 0))' is "Sun Apr 01
0108 02:00:00 GMT+0200" in my Firefox 2.0.0.12; probably not what you want ;-)
6 hours I've been at this....any help would be greatly appreciated. I
just need the day number of the week.
If you make the suggested corrections, it should work.
PointedEars
Mar 24 '08 #2
mt**@mtekusa.com wrote:
Hi,

I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(numbers[2] -
1900,numbers[0],numbers[1]-1))).getUTCDay();

Date comes in as MM/DD/YYYY
alert(new Date("3/25/2008").getDay())

alert(new Date(entered).getDay())

Works in N America.

Mick
>
This works fine, as long as I am looking in the same month within a 3
week period. But choose March 1st (Saturday) or any other day in
another month, and the day number is wrong.

6 hours I've been at this....any help would be greatly appreciated. I
just need the day number of the week.

Thank you,

John
Mar 24 '08 #3
In comp.lang.javascript message <e36e26ec-96c5-487f-a3f0-3bd3890d58f0@c6
5g2000hsa.googlegroups.com>, Mon, 24 Mar 2008 08:07:57, mt**@mtekusa.com
posted:
>
I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(numbers[2] -
1900,numbers[0],numbers[1]-1))).getUTCDay();
Droll.
>Date comes in as MM/DD/YYYY
FFF.

DS = "03/23/2008"
DoW = (new Date(DS+" GMT").getUTCDay()+6)%7+1
or if (!(DoW = new Date(DS+" GMT").getUTCDay())) DoW = 7

will get you the standard result.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mar 24 '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...
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...
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...
1
by: Steph. | last post by:
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 Saturday 01/01/2005 : week = 1
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.