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

Australian Date

Hi,

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.

Any ideas?

Nov 23 '05 #1
17 4078
gi****@gmail.com wrote:
Hi,

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

var time = new Object;
I'm not sure what the JS interpreter will make of that, it doesn't cause
an error but I suspect it isn't doing what you think.

If you really meant to call the Object constructor as a function, then
use '()':

var time = new Object();

time.Date = "24/11/05"; //Nov. 24, 2005
Supposing time is a newly instantiated object, it now has a Date
property of the string "24/11/05". It is equivalent to:

var time = { Date : "24/11/05" };

time.Date is not a date object, it is a string.
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.


I got '24/11/05'.

But if 'time' is to be a date object, and set to a particular value,
declare and initialise it in one go:

var time = new Date(2005, 11, 24);

noting that month numbers are zero-indexed; '11' is December. If you
meant November, then use '10' instead.

Date objects are described in in section 15.9 of the ECMAScript spec.

<URL:http://www.mozilla.org/js/language/E262-3.pdf>

--
Rob
Nov 23 '05 #2
wrote on 23 nov 2005 in comp.lang.javascript:
Hi,

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,
Wrong example, this is not working like you describe:
var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.


<script type='text/jscript'>

var time = new Date("24/11/05"); //Nov. 24, 2005
document.write(time);

// Tue Dec 11 00:00:00 UTC+0100 1906
// +0100 being my set regional time zone

</script>

This code works correctly, as the machine interprets
24/11/05 as the 11th day of the 24th month of 1905

[Depending on your regional setting being dd/mm/yyyy]

===========================

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #3
Evertjan. said the following on 11/23/2005 4:53 AM:
wrote on 23 nov 2005 in comp.lang.javascript:

Hi,

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

Wrong example, this is not working like you describe:

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.

<script type='text/jscript'>

var time = new Date("24/11/05"); //Nov. 24, 2005
document.write(time);

// Tue Dec 11 00:00:00 UTC+0100 1906
// +0100 being my set regional time zone

</script>

This code works correctly, as the machine interprets
24/11/05 as the 11th day of the 24th month of 1905

[Depending on your regional setting being dd/mm/yyyy]

===========================

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Thats a solution, but wasn't the OP's problem. The problem was he wasn't
using a Date Object, he was adding a property to an Object and then
retrieving that String property.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #4
Randy Webb wrote on 23 nov 2005 in comp.lang.javascript:
Evertjan. said the following on 11/23/2005 4:53 AM:
wrote on 23 nov 2005 in comp.lang.javascript:

Hi,

I'm trying to work with the Australian date formats and javascript
and it's causing me quite a headache. I have a date in a "dd/mm/yy"
format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

Wrong example, this is not working like you describe:

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.

<script type='text/jscript'>

var time = new Date("24/11/05"); //Nov. 24, 2005
document.write(time);

// Tue Dec 11 00:00:00 UTC+0100 1906
// +0100 being my set regional time zone

</script>

This code works correctly, as the machine interprets
24/11/05 as the 11th day of the 24th month of 1905

[Depending on your regional setting being dd/mm/yyyy]

===========================

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Thats a solution, but wasn't the OP's problem. The problem was he
wasn't using a Date Object, he was adding a property to an Object and
then retrieving that String property.


Sure, but if so, he would not have experienced the resuld he said.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #5
Evertjan. wrote:

[snip]

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Dec 24, 2005

Mick

Nov 23 '05 #6
Mick White wrote on 23 nov 2005 in comp.lang.javascript:
Evertjan. wrote:

[snip]

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Dec 24, 2005


Wrong quoting, that was not me, that was my quote of the OQ.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #7
Evertjan. said the following on 11/23/2005 12:34 PM:
Mick White wrote on 23 nov 2005 in comp.lang.javascript:

Evertjan. wrote:

[snip]
Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Dec 24, 2005

Wrong quoting, that was not me, that was my quote of the OQ.


Correct quoting, it is in your last line of "solution" to the problem.
<quote>
Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005
</quote>

And in JS that is Dec, not Nov.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #8
Randy Webb wrote on 23 nov 2005 in comp.lang.javascript:
Evertjan. said the following on 11/23/2005 12:34 PM:
Mick White wrote on 23 nov 2005 in comp.lang.javascript:

Evertjan. wrote:

[snip]

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005
Dec 24, 2005

Wrong quoting, that was not me, that was my quote of the OQ.


Correct quoting, it is in your last line of "solution" to the problem.
<quote>
Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005
</quote>

And in JS that is Dec, not Nov.


True

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #9
Randy Webb wrote:
var time = new Date("2005/11/24"); //Nov. 24, 2005
And in JS that is Dec, not Nov.


No it's not. At least in IE, it parses correctly as Nov 24, 2005.
Doing:
var time = new Date(2005,11,24);
would result in Dec 24, 2005.

Although, I don't think that browsers are required to parse yyyy/mm/dd
correctly anyway. So all browsers may not parse it the same.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 23 '05 #10
JRS: In article <11**********************@g43g2000cwa.googlegroups .com>
, dated Tue, 22 Nov 2005 17:01:39, seen in news:comp.lang.javascript,
gi****@gmail.com posted :
I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.


Read the newsgroup FAQ; see below.

Your example is apparently faulty; I get 24/11/05, as expected.

Your browser is merkin-infested, from what you otherwise say :-

MM=24 DD=11 YY=05 === MM=12 DD=11 YY=06 ==> 12/11/2006

You're lucky not to get 1905.

Use "24 Nov 2005" or "2005/11/24" as an argument to new Date() and not
only you but everyone else will get tomorrow's date.

Read the newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.
Nov 23 '05 #11
JRS: In article <En*******************@twister.nyroc.rr.com>, dated
Wed, 23 Nov 2005 17:09:56, seen in news:comp.lang.javascript, Mick White
<mw***********@rochester.rr.com> posted :
Evertjan. wrote:

[snip]

Solution [regional settings independent]:

always use yyyy/mm/dd

var time = new Date("2005/11/24"); //Nov. 24, 2005


Dec 24, 2005


Tested ??

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.
Nov 23 '05 #12
Dr John Stockton said the following on 11/23/2005 2:08 PM:
JRS: In article <11**********************@g43g2000cwa.googlegroups .com>
, dated Tue, 22 Nov 2005 17:01:39, seen in news:comp.lang.javascript,
gi****@gmail.com posted :

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.

Read the newsgroup FAQ; see below.


It won't show the problem with the above code.
Your example is apparently faulty; I get 24/11/05, as expected.
Another manifestation of your mastery of the obvious?
Your browser is merkin-infested, from what you otherwise say :-

MM=24 DD=11 YY=05 === MM=12 DD=11 YY=06 ==> 12/11/2006

You're lucky not to get 1905.


If he got 1905, it would indeed be a bad day. Your browser, no matter
what setting, shouldn't give anything but 24/11/05 when alerting
time.Date as it is not a Date Object but a simple String property
assigned to an Object named time.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 24 '05 #13
"Matt Kruse" <ne********@mattkruse.com> writes:
Randy Webb wrote:
var time = new Date("2005/11/24"); //Nov. 24, 2005
And in JS that is Dec, not Nov.


No it's not. At least in IE, it parses correctly as Nov 24, 2005.
Doing:
var time = new Date(2005,11,24);
would result in Dec 24, 2005.

Although, I don't think that browsers are required to parse yyyy/mm/dd
correctly anyway. So all browsers may not parse it the same.


From the ecma 262 spec:
[FYI: Using new Date(value), with value of type string creates a Date
object with the same date (ticks count) as the one that would be returned
by calling Date.parse(value)]

However:
15.9.4.2: (about Date.parse())
"[...] in general, the value produced by Date.parse is
implementation-dependent when given any string value that could not
be produced in that implementation by the toString or toUTCString
method."

Still, when using the spidermonkey interpreter:
==========================
aundro@paddy:~$ js
js:: new Date().toString()
Thu Nov 24 2005 09:53:55 GMT+0100 (CET)

js:: new Date().toLocaleString()
Thu Nov 24 09:54:06 2005

js:: new Date().toUTCString()
Thu, 24 Nov 2005 08:54:15 GMT

js:: new Date("2005/11/24")
Thu Nov 24 2005 00:00:00 GMT+0100 (CET)
==========================

It appears that the string "2005/11/24" is not required to parse
correctly, since it's very different than what the Date.to*String()
methods return.

So, browsers are indeed not required to parse yyyy/mm/dd correctly,
but the spidermonkey does and therefore probably Mozilla-based
browsers will parse it ok.

(anyway, imagine you read the date from an HTML field that the user
must have filled, are you really gonna ask him to format the date with
"Day Mon DayNr Year hh:mm:ss <timezone>" ? It seems weird..)

Regards,
Arnaud
Nov 24 '05 #14
JRS: In article <n9******************************@comcast.com>, dated
Wed, 23 Nov 2005 17:13:43, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
var time = new Date("2005/11/24"); //Nov. 24, 2005
</quote>

And in JS that is Dec, not Nov.


You tested that ? In which system ?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.
Nov 24 '05 #15
JRS: In article <dm*********@news2.newsguy.com>, dated Wed, 23 Nov 2005
16:33:45, seen in news:comp.lang.javascript, Matt Kruse
<ne********@mattkruse.com> posted :
Randy Webb wrote:
var time = new Date("2005/11/24"); //Nov. 24, 2005
And in JS that is Dec, not Nov.


No it's not. At least in IE, it parses correctly as Nov 24, 2005.
Doing:
var time = new Date(2005,11,24);
would result in Dec 24, 2005.

Although, I don't think that browsers are required to parse yyyy/mm/dd
correctly anyway. So all browsers may not parse it the same.


Since yyyy/mm/dd has only one possible meaning as a Date (*no-one* uses
yyyy/dd/mm, not even in Lookout Mountain Avenue), any browser that
accepts it as a date must, out of sheer reasonableness, accept it as
2005 Nov 24, and others should give NaN.

Except if new Date is prepared to do an implicit eval on the string,
when the result will be very early in 1970 UTC.!

ISTM that new Date(-0) and new Date(+0) represent the same
instant, and have zero difference in value. However, according to ECMA,
they may or may not be distinguishable.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.
Nov 24 '05 #16
JRS: In article <gv******************************@comcast.com>, dated
Wed, 23 Nov 2005 20:21:41, seen in news:comp.lang.javascript, Randy Webb
<Hi************@aol.com> posted :
Dr John Stockton said the following on 11/23/2005 2:08 PM:
JRS: In article <11**********************@g43g2000cwa.googlegroups .com>
, dated Tue, 22 Nov 2005 17:01:39, seen in news:comp.lang.javascript,
gi****@gmail.com posted :

I'm trying to work with the Australian date formats and javascript and
it's causing me quite a headache. I have a date in a "dd/mm/yy" format.
Whenever I try to retrieve that date from my javascript, it'd return
some random date that doesn't make sense.

For example,

var time = new Object;
time.Date = "24/11/05"; //Nov. 24, 2005
alert(time.Date);

Now I'd get something 12/11/2006 in my alert box.

Read the newsgroup FAQ; see below.


It won't show the problem with the above code.
Your example is apparently faulty; I get 24/11/05, as expected.


Another manifestation of your mastery of the obvious?
Your browser is merkin-infested, from what you otherwise say :-

MM=24 DD=11 YY=05 === MM=12 DD=11 YY=06 ==> 12/11/2006

You're lucky not to get 1905.


If he got 1905, it would indeed be a bad day. Your browser, no matter
what setting, shouldn't give anything but 24/11/05 when alerting
time.Date as it is not a Date Object but a simple String property
assigned to an Object named time.


To simulate intelligence, please read my articles carefully before
answering - attempt, in fact, to understand them as if you were an
educated native reader of the English language (or were Dutch, Danish,
etc.), rather than a native reader of American.

In this case you disregarded the word "otherwise", which indicates that,
in the part starting with that sentence, I'm not referring to the code
he gave, but to whatever he used that prompted him to write "Now I'd get
something 12/11/2006 in my alert box.".

YWIII, KETFOB.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.
Nov 26 '05 #17
Dr John Stockton said the following on 11/25/2005 6:20 PM:

<snip>
To simulate intelligence, please read my articles carefully before
answering - attempt, in fact, to understand them as if you were an
educated native reader of the English language (or were Dutch, Danish,
etc.), rather than a native reader of American.
I would argue with that ignorant attitude but you would only drag me
down to your level and defeat me with experience John.

English (and in fact any language) is in the eye of the beholder. It is
not important what you mean but what the reader/listener gets out of it
and that is very simple to prove.
In this case you disregarded the word "otherwise"


Another one of your assumptions?

You got corrected.
You don't like it.
Deal with it and move on John.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 29 '05 #18

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

Similar topics

0
by: Simon Taylor | last post by:
Announcement: OSDC 2005 is up and running. The second Australian OSDC (Open Source Developers' Conference) will be held on the 5th, 6th and 7th of December 2005 at Monash University in...
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
1
by: jack | last post by:
not sure exactly where I should ask this question, but im looking for a database of Australian Postcodes that included the longitude/latitude. Does anyone know of such a thing? Preferably...
2
by: Dean Grubb | last post by:
Is there a faq on this..cause boy it is giving me a headache. System is FreeBSD 4.9 System date returns Tue Nov 25 16:32:36 EST 2003 Postgres Version is 7.3.4 installed from the port collection...
63
by: Martin Johansen | last post by:
Hey guys Since C is my language of choice for almost any kind of application, I'd like to know what the status of C is around the world today. And I am ofcourse not talking about C++ or C#. I...
4
by: Dixie | last post by:
I have a spreadsheet that uses VBA code in Access to save itself as a text file. The line is as follows. xl.ActiveSheet.SaveAs CurrentProject.Path & "\Reports\" & DLookup("", "tblButtons",...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
1
by: alan5 | last post by:
I want to answer on the topic australian postcode db with longitude/latitude posted by jack. He wrote: not sure exactly where I should ask this question, but im looking for a database of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.