2

In my Database i am having date in "dd/mm/yyyy" format. In the sucess function I am getting like '29/06/2006". I want to convert this form "dd/mm/yyyy" format to default format (default format means "Thu Jun 29 2006 00:00:00 GMT+0530 (India Standard Time)")

I tried the following ways

1) way

xx = 29/06/2006 
new Date(xx)

2)way

dateFormat(xx, "ddd, mmmm dS, yyyy, h:MM:ss TT")

Both giving wrong date,month,year. Result as (Tue, May 6th, 2008, 12:00:00 AM)

I am giving input as Jun 29 2006 but after conversion it'a showing May 6th, 2008.

pyvi
  • 675
  • 1
  • 4
  • 15
vinothini
  • 2,606
  • 4
  • 27
  • 42
  • There is a similar question about this at http://stackoverflow.com/questions/476105/how-can-i-convert-string-to-datetime-with-format-specification-in-javascript – zaboco Aug 16 '11 at 09:20

3 Answers3

1

Try this:

var mydate = new Date(getDateFromFormat(/*Date value in string*/, /*Format of date sting*/));

http://www.mattkruse.com/javascript/date/

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Surendra
  • 237
  • 3
  • 6
  • 19
0

check javascript dateFormat

Shebin
  • 3,310
  • 2
  • 24
  • 27
0

this could do it:

var dt  = '01/05/2011'.split(/\-|\s/)  // allows for 01-05-2011 also
    dat = new Date(dt.reverse().join('/'));
KooiInc
  • 119,216
  • 31
  • 141
  • 177