Solved

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

Posted on 2008-09-30
2
4,472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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

617 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