473,785 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(n umbers[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 1435
mt**@mtekusa.co m wrote:
I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(n umbers[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(1 08, 3, 0)).getUTCDay() ;

The string representation of `new Date(Date.UTC(1 08, 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.co m 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(n umbers[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).g etDay())

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.javas cript message <e36e26ec-96c5-487f-a3f0-3bd3890d58f0@c6
5g2000hsa.googl egroups.com>, Mon, 24 Mar 2008 08:07:57, mt**@mtekusa.co m
posted:
>
I am using this code to get the day number of the week:

var numbers = entered.split('/');
var daynum = (new Date(Date.UTC(n umbers[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.demo n.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.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
5219
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 appreciated. TIA
7
15149
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 attached), yet when I ran it for 28/09/2003 (UK date format) it returned Week 39. I would have expected it to return Week 40. However, I'm really stuck and my head is busting over this, so any pointers would be gratefully appreciated. Many thanks...
14
5110
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 DateAdd("d", 6, DateAdd("d", -weekday()+2,)))
9
3420
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 period and 13 periods a year. normally 52 weeks per year but one 53-week a year every 6 years. The 53th week is included in period 13. Can someone advise any idea how to construct such conversion.
1
1534
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
6102
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
17339
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 common factor. Mal.
6
25369
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 1953 I checked the algorithm it is very correct.
10
1251
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 month of my choosing. Let me explain; I can get my week numbers no problem. I can get the date from the week numbers no problem. What I haven't been able to do is put things together and make a simple function that will allow my users to select from...
0
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.