0

I am working on a jquery calendar script. In the script, selecting a row gives a date object as callback.

select: function(start, end, allDay) {
                       $("#datepicker_add").val(start);
                       $("#datepicker_add_end").val(end);
                    calendar.fullCalendar('renderEvent',
                        {
                            title: title,
                            start: start,
                            end: end,
                            allDay: allDay
                        },
                        true // make the event "stick"
                    );

                calendar.fullCalendar('unselect');
            },

Here that start and end objects are like that Wed Aug 22 2012 00:00:00 GMT+0300 (EEST) What i want is to format this as Y-m-d

How can i do that ?

Utku Dalmaz
  • 9,780
  • 28
  • 90
  • 130

3 Answers3

0
var date = new Date("Wed Aug 22 2012 00:00:00 GMT+0300 (EEST)");
var dateString = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + (date.getDate()+1);
console.log(dateString);
Aletheios
  • 3,960
  • 2
  • 33
  • 46
0

if you use Jquery UI as well you can use the DataPicker's static convert methods:

$.datepicker.formatDate('mm-dd-yy', DateToConvert); //requires jquery ui

you could also create a new Javascript date object and pass in your desired object off the get-go or use the various "get" functions to pull the pieces you want and reassemble as you need to:

http://www.w3schools.com/js/js_obj_date.asp

muck41
  • 288
  • 2
  • 9
0

you may use this lib i made before

http://code.google.com/p/javascript-date-util/

you can check a function called getDayString(date, separator) and you can send it the date you want to stringify and the separator you'd like to have.

Prog Mania
  • 615
  • 9
  • 14