0

How can I display today's date with minus 5 days in below format?

Today's date: 18/03/2016

Last sync date: 13/03/2016

I have tried the with below example though I am able to achieve today's date, not before 5 days date...

PS: I have tried with alert(todayDate) - 5 without luck :(

Any help please?

var d = new Date();
var month = d.getMonth()+1;
var day = d.getDate();
var todayDate = ((''+day).length<2 ? '0' : '') + day + '/' +  ((''+month).length<2 ? '0' : '') + month + '/' + d.getFullYear();
alert(todayDate);

I'm using jQuery if that's relevant.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Reddy
  • 1,477
  • 29
  • 79
  • This has nothing to do with jQuery. It's a JavaScript question. – T.J. Crowder Mar 18 '16 at 07:28
  • 3
    Duplicate http://stackoverflow.com/questions/13838441/javascript-how-to-calculate-the-date-that-is-2-days-ago http://stackoverflow.com/questions/1296358/subtract-days-from-a-date-in-javascript – Reagan Gallant Mar 18 '16 at 07:31
  • Got the answer... `var todayDate = ((''+day).length<2 ? '0' : '' - 5) + day + '/' + ((''+month).length<2 ? '0' : '') + month + '/' + d.getFullYear();` – Reddy Mar 18 '16 at 07:44

0 Answers0