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

Simple Date Function Error

Hi, I've written a simple script to test the current date and perform
an action depending on the result.
The problem is, the date displays correctly as a complete date in an
alert box but when I try to build the date from the components (i.e
d.getMonth() etc...) the result is an incorrect date.
How can the date be both correct and incorrect at the same time? The
intial alert(d); displays correctly, but the alert(t + "/" + m + "/" +
y); does not.
Is it heisenbergs uncertainty principle at work?

here's my code...

<script language="javascript" type="text/javascript">

var d;
d = new Date();

//get the date properties
t = d.getDay();
m = d.getMonth();
y= d.getYear();

//display the full date from the Date object.
alert(d);
//display the date for debugging purposes
alert(t + "/" + m + "/" + y);

//test if it's between April and September
if ((m > 4) && (m < 9))
{
//perform a conditional action
alert("out of the season");
}
else
{
alert("in the season");
}

</script>

it's a mystery... any ideas.

appreciated.

David Thomas.
Jul 23 '05 #1
3 1229
David Thomas wrote:
<snip>
Is it heisenbergs uncertainty principle at work?
The only uncertainty is yours in not knowing how javascript Date objects
represent and report dates.

<snip> m = d.getMonth(); <snip> //test if it's between April and September
if ((m > 4) && (m < 9)) <snip>

The number returned from - getMonth - in zero based (zero is January).
it's a mystery... any ideas.


RTFM.

Richard.
Jul 23 '05 #2
Thanks for that. You are absolutely right. I actually did a bit of
research and discovered the javascript 0 based getMonth(); scenario (i.e
january = 0, february 1 etc...)
I was also using getDay(); to return the date of the month when I should
have been using getDate(); so that explains it. thanks for your
feedback, I'm sure Mr Heisenberg would approve. The uncertainty was only
within my limited sphere of knowledge at the time. When it comes to
computers, there seems to be a rational explanation for everything.

kind regards,

D.Thomas.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
JRS: In article <40**********************@news.newsgroups.ws>, seen in
news:comp.lang.javascript, David Thomas <da***********@hotmail.com>
posted at Thu, 1 Jul 2004 13:07:03 :
Thanks for that. You are absolutely right. I actually did a bit of
research and discovered the javascript 0 based getMonth(); scenario (i.e
january = 0, february 1 etc...)
I was also using getDay(); to return the date of the month when I should
have been using getDate(); so that explains it. thanks for your
feedback, I'm sure Mr Heisenberg would approve.


Professor Werner Heisenberg (1901-76) should be given his proper style.
He had a Chair at Leipzig by 1930, and a Nobel Prize in 1932. I recall
attending a lecture by him.

If you had used the newsgroup FAQ with care, your problems should not
have occurred; see below.

Code should be indented, to show its logical structure.

Dates should be presented with leading zeroes for month % day,
preferably as YYYY-MM-DD or YYYY/MM/DD.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

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

Similar topics

5
by: gsv2com | last post by:
Maybe I'm tired, but I'm having a small problem with a date function I'm writing. Total noobish I know, but this is just going beyond me for some reason... What I want to happen is send a date...
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...
1
by: Jill | last post by:
I am trying to store the current date to an ms access database on my server. I set it up with a dsnless connection. Here is the statement: Insert Into employees(timestamp) Values ('" & date() &...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
4
by: merlin | last post by:
greetings to all. i am new to the group and to access. I am using access 97 to setup our clinic's database and in one of the tables I need to be able to type in a date only in terms of the...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
6
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future,...
3
by: bhavu10 | last post by:
hi i have created a form forreport with today, week month & year CMD Button but i think i wrote the code wrong for month and also it shows me only records for this year whewe as i have 2006...
2
by: LadySugar | last post by:
Greetings! I have a database in access that contains information about the date members joined the company. Every year, membership must be renewed for each member. Usually I will send out a...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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...

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.