Convert dd.mm.yyyy format to yyyy-mm-dd

javascript

Solution

Datejs can parse that. The code is at http://datejs.googlecode.com/files/date.js

EDIT: It is not safe to left date.js determine the format string automatically. I made the mistake of not testing with a day <= 12 (duh). You should use:

Date.parseExact('09.01.2010', 'd.M.yyyy').toString('yyyy-MM-dd');

or

Date.parseExact('09.01.2010', 'dd.MM.yyyy').toString('yyyy-MM-dd');

depending on whether you want to allow single digit days.

Problem

How can I convert dd.mm.yyyy format date to yyyy-mm-dd format in JavaScript? Here is an example: ``` 30.01.2010 to 2010-01-30 ``` Meaning convert d.m.Y to Y-m-d. I know how to do this in PHP but I need it in JavaScript.

Original source