-2

I am trying to convert the date to yyyy-mm--dd this format.Here is my code .can anyone please tell me how to do?

var curr_date = new Date(date - i*86400000);

Output of the code is coming like this

Thu Jul 17 2014 10:37:44 GMT+0530 (India Standard Time)

but i need the output like year-mm-dd.

I am trying this also for year-mm-dd .this is working fine.

var date = new Date();
var date_format =(date.getFullYear()  + '-' + (date.getMonth()+1) + '-' +  date.getDate());

but i want to convert

var curr_date = new Date(date - i*86400000);

to yyyy-mm--dd how to append var date_format and var curr_date

Devjosh
  • 6,350
  • 4
  • 35
  • 59
Sujitha
  • 105
  • 1
  • 1
  • 6
  • Here i am decrementing the current date to one day for 7 days.thats y i used "var curr_date = new Date(date - i*86400000);" I want these 7days date should be like this yyyy-mm-dd. – Sujitha Jul 17 '14 at 05:54
  • "how to append var date_format and var curr_date" I have no idea what you are talking about, what do you want to do? – Tobias Jul 17 '14 at 05:56
  • Hi guys ,I got the solution .Thank you for suggestions – Sujitha Jul 17 '14 at 06:30

2 Answers2

0

Use FormatDate
$.datepicker.formatDate('yyyy-mm-dd', new Date(date - i*86400000));

Reference Jquery UI:

Arijit Mukherjee
  • 3,449
  • 2
  • 29
  • 47
0

This will do the trick.

var date = new Date();
var d = new Date(date - i*86400000);
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var date_format = curr_year + "-" + curr_month + "-" + curr_date;
sharf
  • 2,075
  • 3
  • 15
  • 40