473,503 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read XML date (d/M/y) format & convert to date object

31 New Member
Hi,

I have some XML data which contains a date in dd/mm/yyyy format (ie UK date format).

In javascript I need to read this date then calculate the age (in days& decimals) of the XML data.

I can get today's date in milliseconds:
Expand|Select|Wrap|Line Numbers
  1. var current_date = new Date();
  2. var date1_ms = current_date.getTime();
but I can't see how to read the XMLdate in UK format, I have the XML date (string) in a var called docdate & I thought this should work:

Expand|Select|Wrap|Line Numbers
  1.    var date2 = Date.parseString(docdate,"d/M/yyyy");
  2. var date2_ms = date2.getTime();
Then I can sutract date1_ms from date2_ms to get the age in milliseconds, but the Date.parseString(docdate,"d/M/yyyy"); doesnt work. and my alternative of:
var date2=Date/parse(docdate."d/M/yyyy")
ignores my format command and reads the date as US format.

Can any one give me the correct line oif code, or a better one:-) or point me to a reference. Everything I;ve found formats the date for OUTPUT rather than INPUT.
Thanks.
Sep 12 '07 #1
6 3229
pbmods
5,821 Recognized Expert Expert
Heya, Gretsch.

To output a date in a custom format, you'll have to use Date::getYear(), Date::getDay(), etc. and manually build the string piecemeal.
Sep 12 '07 #2
Gretsch
31 New Member
Thanks pbmods,

...but I assume Date::getMonth() would get the first 2 digits of my dateString (in the mistaken belief that it was in US date format)
.. or have I misunderstood your suggestion?
Sep 13 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Gretsch.

Good point.

To do that, you will have to create an array and reference its index. E.g.,
Expand|Select|Wrap|Line Numbers
  1. var months = ['Jan', 'Feb', 'Mar', ..., 'Dec'];
  2. alert(months[theDate.getMonth() - 1]);
  3.  
Sep 13 '07 #4
mrhoo
428 Contributor
the getMonth and other Date methods don't work on strings, but only on Date objects. You don't need to worry about reading a date, but about the way you create the Date from your string input.

If you are using a dd/mm/yyyy formatted string you can assemble the Date by splitting the string on non digits and using the returned array elements-
Expand|Select|Wrap|Line Numbers
  1. var dString= '01/08/2007';
  2. var dArray= dString.split(/\D+/);
  3. var dDate= new Date(dArray[2],dArray[1]-1,dArray[0]);
Sep 14 '07 #5
Gretsch
31 New Member
Excellent - thanks very much
Sep 14 '07 #6
pbmods
5,821 Recognized Expert Expert
Heya, Mr. Hoo.

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
Sep 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
42977
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
3
2435
by: J. Muenchbourg | last post by:
while inserting new records into SQL, i'm using the folloinwg sqlstatement> Dim MySQL as string = "Insert into roster (pname, pnotes, thedate) values (@pname, @pnotes, @thedate)" the sql...
5
16280
by: goochey | last post by:
I'm trying to convert a Julian Date (Format "4365") into an actual calendar date in Visual Basic, can anyone help me out with this.
2
1780
by: [Yosi] | last post by:
DateTime dd = DateTime.ParseExact ("27/09/2003", "dd/MM/yyyy"); I still get an error : "(939): No overload for method 'ParseExact' takes '2' arguments" >-----Original Message----- >Dates...
4
5553
by: jty202 | last post by:
I have string that contains a date in this format (14-Jan-05). I want to store in date object if theres one and access each part of the date (month, year, dates, day of week). Specifically I...
12
3826
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
12
26886
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate"...
7
1983
by: JamesG | last post by:
Hi, I need to convert the current time to the format "hh:mm:ss" and date to the format "yyyy-MM-dd". The result of both conversions needs to be of System.DateTime format. I've tried using...
2
16765
by: thewilldog | last post by:
Hello, I've reviewed the archives here to address the issue, but I'm still running into problems. I've got a table field populated with the record date in text "YYYYMMDD" To convert it into a...
0
7192
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
7261
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
7315
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...
1
6974
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
7445
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...
1
4991
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...
0
3158
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...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
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...

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.