473,789 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Split & Parts" different results in Firefox & IExplorer

The following code is supposed to reverse the date in "yyyy-mm-dd" format,
but it produces different results in Firefox 1.0 and in Internet Explorer
6SP1. In Firefox, the result is correct ("2004-11-29") but it's wrong in
Internet Explorer 6SP1 ("00:20:15-11-29"). If I change "dateParts[3]" to
"dateParts[4]", it's exactly the opposite that occures: a correct result in
IExplorer but a fault in Firefox. Is there a workaround? Where do I miss the
point??
function SplitDate()
{
// Split current date.
today = Date();
dateParts = today.split(" ");

// Assign splitted date parts to variables.
year=dateParts[3];
month=GetMonthN umber(dateParts[1]);
day=dateParts[2];

// Build date in "yyyy-mm-dd" format
dateStamp = year + "-" + month + "-" + day;
}

Result in Firefox 1.0 is => 2004-11-29
Result in Internet Explorer 6 => 00:20:15-11-29

Kinne
Jul 23 '05 #1
4 2430
kinne wrote:
The following code is supposed to reverse the date in "yyyy-mm-dd" format,
but it produces different results in Firefox 1.0 and in Internet Explorer
6SP1. In Firefox, the result is correct ("2004-11-29") but it's wrong in
Internet Explorer 6SP1 ("00:20:15-11-29"). If I change "dateParts[3]" to
"dateParts[4]", it's exactly the opposite that occures: a correct result in
IExplorer but a fault in Firefox. Is there a workaround? Where do I miss the
point??


You are depending upon the browser's default date format to fit your
script - not a good idea, particularly when you can access the parts of
the date directly and hence, reliably.

Try this:

<script type="text/javascript">
function iso8601date(){
var aDate = new Date();
var dateNum = aDate.getDate() ;
var monthNum = +aDate.getMonth () + 1; // month range is 0-11
var yearNum = aDate.getFullYe ar();
alert('date is ' + yearNum
+ '-' + LZ(monthNum)
+ '-' + LZ(dateNum)
);
}

function LZ(x) { return (x<0||x>=10?"": "0") + x }
</script>

You may want not want to add leading zeros to single digit months and
days - it isn't necessary for ISO 8601 compliance but some think it
looks better.

LZ() courtesy of an earlier post by Dr John Stockton.

If you are going to use dates input by the user, then you must do a lot
of validation on the string that is input and on date ranges -
different browsers support different ranges (e.g. Safari has a range of
1900 to 2038, other browsers have much greater ranges) so you must
validate that the date created from the input is a valid date.

Search for date posts, you will find plenty of good advice.

--
Rob
Jul 23 '05 #2
JRS: In article <f%************ *****@news.optu s.net.au>, dated Mon, 29
Nov 2004 00:24:43, seen in news:comp.lang. javascript, RobG
<rg***@iinet.ne t.auau> posted :

function LZ(x) { return (x<0||x>=10?"": "0") + x }
</script>

You may want not want to add leading zeros to single digit months and
days - it isn't necessary for ISO 8601 compliance but some think it
looks better.

<BIG><BIG><BI G> HO YES IT IS NECESSARY </BIG></BIG></BIG>

ISO8601:2000(E) 5.2.1 is clear; and probably so for other values of E.

The year, except by agreement, should also be four digits (more after
9999).

In Y-D dates, D must be 3 digits.

Unless field lengths are constant, and separators do not fluctuate, the
full advantages of 8601 do not accrue - fixed-length dates can be sorted
as strings, fields can be extracted by position, ...

I predict an update, ISO8601:9???, making 5-digit years mandatory.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
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.
Jul 23 '05 #3
Dr John Stockton wrote:
[...]

<BIG><BIG><BI G> HO YES IT IS NECESSARY </BIG></BIG></BIG>

ISO8601:2000(E) 5.2.1 is clear; and probably so for other values of E.

Yes, quite correct. I can't think where I go the idea from. I've been
working extensively with metadata standards and absolutely should have
known - I can only think some brain-bits got flipped the wrong way.

[...] I predict an update, ISO8601:9???, making 5-digit years mandatory.


And you owe me a beer if it hasn't happened by 9999-12-31.

--
Rob
Jul 23 '05 #4
> You are depending upon the browser's default date format to fit your
script - not a good idea, particularly when you can access the parts of
the date directly and hence, reliably.

Try this:

[snip]
Thanks a lot: your solution works fine in both browsers.

François
Jul 23 '05 #5

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

Similar topics

23
5687
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've reduced my form request to a simple text string entry, instead of my desired optional parameters. As i have been stuck with a single unfathomable glitch for over a year. Basically, if i enter queries such as ; "select * from table" "select * from...
11
2509
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of strings. I wonder if someone else had ever stumbled on it before, and if it has a good reason to work like it is. Both implementations take two parameters: the separator character and the max number of splits (maxsplit). However, string.split() accept
5
3449
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot; &lt;me@mydomain.com&gt;</Address> </Addresses>
11
12623
by: pmarisole | last post by:
I am using the following code to split/join values in a multi-select field. It is combining all the values in All the records into one long string in each record in recordset. Example: I have a recordset with 2 records. The 1st contains the split/joined values: Alan Smir, Jeff Karl The 2nd contains the value: Keith Robb When it updates database, it will put Alan Smir, Jeff Karl, Keith Robb into each record in the recordset
1
2940
by: EoRaptor013 | last post by:
Not sure where to ask this question, but... I'm using a TreeView component to enable browsing file folders in a specific directory (for test purposes /Program Files/). Some users use an ampersand ("&") in both folder and file names. This has caused me some real grief! I'm not in a position to tell the users it's an ID 10 T error and they have to change their file and folder names. In VS2K5, I have debugged my code and found that ...
14
5936
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only because of this, so I hope some of you gurus can enlighten me with this :) In what circumstances can the "&amp;" in the source code be involuntary changed to "&" by a browser when or other software, when editing and uploading the file to the web...
3
1707
by: albert.neu | last post by:
Hello! What is the difference between "library parts" of C99 and "language parts" of C99. see http://groups.google.at/group/microsoft.public.vc.language/browse_thread/thread/e9a67f0ff20a954b/bd2bada2bbdbce56?lnk=st&rnum=1#bd2bada2bbdbce56 I know that "Dinkum Compleat Libraries" (http://www.dinkumware.com/) support the "library parts" of C99 - this probably relates to the C99
0
13756
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have a table (tblMember) containing information for various people. Table Name=tblMember Field; Type; IndexInfo MemberID; AutoNumber; PK Surname; String
30
3855
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at the end of the app for example: class test { public: int x;
0
10374
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
10177
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
9969
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
8998
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5405
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
5540
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4078
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
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2898
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.