Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-09-30
2
Medium Priority
?
4,483 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 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

722 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