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

Home Posts Topics Members FAQ

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="javas cript" 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 1262
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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
1729
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 (such as June 31, an invalid date) and have the function turn it into a real date by subtraction. In other words, the function would turn the date to June 30, run itself again, and if June 30 is a real date, it'd return it back to the program. ...
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
1
2075
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() & "')" the timestamp field is of type date/time in the ms access database. I get an error saying the insert statement is invalid. Cannot get you the exact error, my server is down. But it seems that the syntax is correct.
1
2488
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. Function DateCalc (blah...) As Variant Do Stuff... If Not IsNull(varNewDate) Then DateCalc = varNewDate End If End Function
4
1449
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 Month/Year format? How do I do that? I can't seem to be able to find this either through the help file or with playing around with the properties. I know it's a silly one but we all have to start from as low as this lol :) thanks in advance
18
3043
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
14373
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, excluding holidays and weekends.' I didn't want to build a table of holidays that would have to be continuously updated, so I searched high and low for a function that would tell me whether a given date was a holiday, to no avail. I did find an...
3
1626
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 records too code is written in Event Procedure of Respective Cmd Button Can there be a problem in TODAY'S Cmd Button code that it shows me only 2007 record PLEASE HELP. Private Sub cmdMonth_Click()
2
2014
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 standard letter from a report to each member regardless of the date they joined. Members are only supposed to receive letters an exact year after they joined. I am wondering if it is possible for me to do a setting that will let me to create reports...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
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
10152
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...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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?
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
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.