Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript create date object from mm/dd/yy or dd/mm/yy

Posted on 2008-09-30
2
Medium Priority
?
4,501 Views
Last Modified: 2012-06-27
Hi
I have date field in dd/mm/yy format (or mm/dd/yy format) and need to convert to javascript date object.
How do I do this? Please provide code snippet....I'm sure this can't be too difficult but haven't found solution
Thanks!
0
Comment
Question by:rwallacej
2 Comments
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 2000 total points
ID: 22608877
try this
dateParts = "dd/mm/yy".split("/");
var date = new Date(dateParts[2], parseInt(dateParts[1]) - 1, dateParts[0]);

or

var date = Date.parse("dd/mm/yy");

or

dateParts = "dd/mm/yy".split("/");
var dateStamp = Date.UTC(dateParts[2], parseInt(dateParts[1]) - 1, dateParts[0]);

that last one converts it to a unix time stamp that you can use in the date methods.
0
 

Author Comment

by:rwallacej
ID: 22608919
hi MMDeveloper

Thanks for input.

I tried with the
new Date(yy, mm-1, dd)
but doesn't work.....seems like you need 'yy' as 'yyyy' e.g. 1990 instead of 90.

I overcame whole issue by setting format of calendar to be dd/mm/yyyy, but a solution to this would be good if possible.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question