473,569 Members | 2,844 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.parseStrin g(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 3237
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=javascrip t]
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
42986
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 mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our...
3
2444
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 parameter I'm using is > cmd.Parameters.Add(New SQLParameter("@thedate", thedate.text))
5
16298
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
1789
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 of that format are ambiguous. It's probably trying
4
5557
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 want to convert it in this format 20050114 because this way, I can compare it with another date in this format to see which is greater. Can something...
12
3832
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
26927
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" datetime field .
7
1990
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 DateTime.ParseExact and DateTimeFormatInfo but failed, most examples I see convert the final result to a string... I dont want that!
2
16771
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 recognizable date format, I've done the following: Query 1: References Source Table; Isolates Year, Day; creates MMDD field Acc Open Year: Left(,4)...
0
7695
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...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6281
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...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
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...
0
3653
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...
1
2111
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
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
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...

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.