Solved

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

Posted on 2008-09-30
2
4,449 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

710 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