dev1234
dev1234

Reputation: 5716

get tomorrows date with jquery and compare

how is it possble to get the date in this format ? 28/09/2013

what i am getting now is,

Fri Sep 27 2013 15:19:01 GMT+0530 (Sri Lanka Standard Time)

This is the code i have written to get that..

 var date = new Date();
 var tomorrow = new Date(date.getTime() + 24 * 60 * 60 * 1000);
 alert(tomorrow);

and i need to see weather, is the given date is tomorrow. something like this when i give 28/09/2013 it should alert as tomorrow or not.

any help is highlight appreciated.

NOTE : i only need to compare with date. 28/09/2013 === tomorrow

Upvotes: 1

Views: 26970

Answers (4)

Nishu Tayal
Nishu Tayal

Reputation: 20880

You can try following to get the next day :

var myDate=new Date();
myDate.setDate(myDate.getDate()+1);
// format a date
var dt = myDate.getDate() + '/' + ("0" + (myDate.getMonth() + 1)).slice(-2) + '/' + myDate.getFullYear();
console.log(dt);

Here is the demo : http://jsfiddle.net/5Yj3V/3/

Upvotes: 8

Saranya Sadhasivam
Saranya Sadhasivam

Reputation: 1294

Try the below fiddle using javascript.

var tomorrow = new Date(); 
var newdate = new Date();
var month = (newdate.getMonth()+1);
newdate.setDate(tomorrow.getDate() + 1);
if (month < 10)
{
    month = '0' + (newdate.getMonth()+1);
}

alert(newdate);
alert(newdate.getDate() + '/' + month + '/' + newdate.getFullYear());

Upvotes: 1

Silviu Burcea
Silviu Burcea

Reputation: 5348

Moment.js will do that for you very easily.

moment().add('days', 1).format('L');

Upvotes: 6

Nadeem_MK
Nadeem_MK

Reputation: 7699

I would use the DateJS library.

var tomorrow = new Date.today().addDays(1).toString("dd-mm-yyyy"); 

Upvotes: 4

Related Questions