How to properly get the date 3 days before the given, if I have a format like 07/21/2017 8:30 AM , this is because I use the format of Eonasdan DateTime Picker. But when I try to minus it with 3 days I got Fri Jul 21 2017 08:24:14 GMT+0800 (China Standard Time) as my value but my desired output should be the same format like 07/21/2017 8:30 AM. How can I get that the value even I follow my format?
My codes:
var d =new Date('07/21/2017 8:30 AM');
var yesterday = new Date(d.getTime() - (96*60*60));
alert(yesterday);
function formatDate(d) {
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
date = [month, day, year].join('/');
var hours = d.getHours();
var minutes = d.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return date+" "+strTime;
}
var d =new Date('07/21/2017 8:30 AM');
d.setDate(d.getDate() - 3);
var yesterday = formatDate(d);
alert(yesterday);
This should work
This should do the trick:
var date = new Date('07/21/2017 8:30 AM'); // get
date.setDate(date.getDate() - 3);
console.log(date.toString());
Basically, it takes the current day with getDate() and uses setDate() to update the time to 3 days in the past.
If you want to format your date, look into moment.js like #Robert said. You could use something like:
moment().format('MM/DD/YYYY, h:mm:ss a');
More information on the Date class here and moment documentation here.
Try using this
var d = new Date();
var d =new Date('07/21/2017 8:30 AM');
var yesterday = d;
yesterday.setDate(d.getDate()-3);
alert(yesterday);
You can simply subtract days from the Date E.g d.getDate() - 3
var d =new Date('07/21/2017 8:30 AM');
d.setDate(d.getDate() - 3);
alert(d)
You need to use setDate function on Date class to change the date part of a date variable
var d =new Date('07/21/2017 8:30 AM');
d.setDate(d.getDate() - 3);
console.debug(d);
Related
This question already has answers here:
How to add days to Date?
(56 answers)
Incrementing a date in JavaScript
(19 answers)
How can I add 1 day to current date?
(10 answers)
Closed 12 months ago.
I am trying to get JavaScript to display tomorrows date in format (dd-mm-yyyy)
I have got this script which displays todays date in format (dd-mm-yyyy)
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
Displays: 25/2/2012 (todays date of this post)
But how do I get it to display tomorrows date in the same format i.e. 26/2/2012
I tried this:
var day = currentDate.getDate() + 1
However I could keep +1 and go over 31 obviously there are not >32 days in a month
Been searching for hours but seems to be no answer or solution around this?
This should fix it up real nice for you.
If you pass the Date constructor a time it will do the rest of the work.
24 hours 60 minutes 60 seconds 1000 milliseconds
var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
One thing to keep in mind is that this method will return the date exactly 24 hours from now, which can be inaccurate around daylight savings time.
Phil's answer work's anytime:
var currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);
The reason I edited my post is because I myself created a bug which came to light during DST using my old method.
The JavaScript Date class handles this for you
var d = new Date(2012, 1, 29) // month is 0-based in the Date constructor
console.log(d.toLocaleDateString())
// Wed Feb 29 2012
d.setDate(d.getDate() + 1)
console.log(d.toLocaleDateString())
// Thu Mar 01 2012
console.log(d.getDate())
// 1
Method Date.prototype.setDate() accepts even arguments outside the standard range and changes the date accordingly.
function getTomorrow() {
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1); // even 32 is acceptable
return `${tomorrow.getFullYear()}/${tomorrow.getMonth() + 1}/${tomorrow.getDate()}`;
}
Using JS only(Pure js)
Today
new Date()
//Tue Oct 06 2020 12:34:29 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0, 0))
//Tue Oct 06 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0,0)).toLocaleDateString('fr-CA')
//"2020-10-06"
Tomorrow
new Date(+new Date() + 86400000);
//Wed Oct 07 2020 12:44:02 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0, 0) + 86400000);
//Wed Oct 07 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0,0)+ 86400000).toLocaleDateString('fr-CA')
//"2020-10-07"
//don't forget the '+' before new Date()
Day after tomorrow
Just multiply by two ex:- 2*86400000
You can find all the locale shortcodes from https://stackoverflow.com/a/3191729/7877099
I would use the DateJS library. It can do exactly that.
http://www.datejs.com/
The do the following:
var d = new Date.today().addDays(1).toString("dd-mm-yyyy");
Date.today() - gives you today at midnight.
The below uses a combination of Roderick and Phil's answers with two extra conditionals that account for single digit months/days.
Many APIs I've worked with are picky about this, and require dates to have eight digits (eg '02022017'), instead of the 6 or 7 digits the date class is going to give you in some situations.
function nextDayDate() {
// get today's date then add one
var nextDay = new Date();
nextDay.setDate(nextDay.getDate() + 1);
var month = nextDay.getMonth() + 1;
var day = nextDay.getDate();
var year = nextDay.getFullYear();
if (month < 10) { month = "0" + month }
if (day < 10) { day = "0" + day }
return month + day + year;
}
Use cases :
Date.tomorrow() // 1 day next
Date.daysNext(1) // alternative Date.tomorrow()
Date.daysNext(2) // 2 days next.
IF "tomorrow " is not depend of today but of another Date different of Date.now(), Don't use static methods but rather you must use non-static :
i.e: Fri Dec 05 2008
var dec5_2008=new Date(Date.parse('2008/12/05'));
dec5_2008.tomorrow(); // 2008/12/06
dec5_2008.tomorrow().day // 6
dec5_2008.tomorrow().month // 12
dec5_2008.tomorrow().year //2008
dec5_2008.daysNext(1); // the same as previous
dec5_2008.daysNext(7) // next week :)
API :
Dateold=Date;function Date(e){var t=null;if(e){t=new Dateold(e)}else{t=new Dateold}t.day=t.getDate();t.month=t.getMonth()+1;t.year=t.getFullYear();return t}Date.prototype.daysNext=function(e){if(!e){e=0}return new Date(this.getTime()+24*60*60*1e3*e)};Date.prototype.daysAgo=function(e){if(!e){e=0}return Date.daysNext(-1*e)};Date.prototype.tomorrow=function(){return this.daysNext(1)};Date.prototype.yesterday=function(){return this.daysAgo(1)};Date.tomorrow=function(){return Date.daysNext(1)};Date.yesterday=function(){return Date.daysAgo(1)};Date.daysNext=function(e){if(!e){e=0}return new Date((new Date).getTime()+24*60*60*1e3*e)};Date.daysAgo=function(e){if(!e){e=0}return Date.daysNext(-1*e)}
Method 1: If you don't have problem in using other library, then this could work for you using moment.js
moment().add('days', 1).format('L');
Method 2: Using Date.js,
<script type="text/javascript" src="date.js"></script>
var tomorrow = new Date.today().addDays(1).toString("dd-mm-yyyy");
This method uses external library and not the native Date library.
As my bootstrap-datetimepicker was using moment.js and native date library, I preferred method 1. This question mentions these and some other methods.
Its really simple:
1: Create date object with today' date and time.
2: Use date object methods to retrieve day, month and full year and concatenate them using the + operator.
Sample Code:
var my_date = new Date();
var tomorrow_date = (my_date.getDate() + 1) + "-" + (my_date.getMonth() + 1) + "-" + my_date.getFullYear();
document.write(tomorrow_date);
function getMonday(d)
{
// var day = d.getDay();
var day = #Config.WeekStartOn
diff = d.getDate() - day + (day == 0 ? -6 : 0);
return new Date(d.setDate(diff));
}
The same as the original answer, but in one line:
var tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000)
The numbers stand for 24 hours 60 minutes 60 seconds 1000 milliseconds.
you can try this:
function Tomorrow(date=false) {
var givendate = (date!=false) ? new Date(date) : new Date();
givendate.setDate(givendate.getDate() + 1);
var day = givendate.getUTCDate()
var month = givendate.getUTCMonth()+1
var year = givendate.getUTCFullYear()
result ="<b>" + day + "/" + month + "/" + year + "</b>";
return result;
}
var day = Tomorrow('2020-06-30');
console.log('tomorrows1: '+Tomorrow('2020-06-30'));
console.log('tomorrows2: '+Tomorrow());
//to get date of tomorrow
let tomorrow=new Date(`${(new Date()).getFullYear()}-${(new Date()).getMonth()+1}-${(new Date()).getDate()+1}`);
//for dd-mm-yy format
tomorrow=`${tomorrow.getDate()}-${tomorrow.getMonth()+1}-${((tomorrow.getFullYear()).toString()).slice(-2)}`;
document.write(tomorrow)
//-----------Date Configuration march 18,2014----------------------
//alert(DateFilter);
var date = new Date();
y = date.getFullYear(), m = date.getMonth();
var EndDate = new Date();
switch (DateFilter) {
case 'today': var StartDate = EndDate; //todays date
break;
case 'yesterday':
var d = new Date();
var previousDate = new Date(d.getTime() - 1000 * 60 * 60 * 24);
var StartDate = new Date(previousDate.yyyymmdd()); //yesterday Date
break;
case 'tomorrow':
var d = new Date();
var NextDate = new Date(d.getTime() + 1000 * 60 * 60 * 24);
var StartDate = new Date(NextDate.yyyymmdd()); //tomorrow Date
break;
case 'thisweek': var StartDate = getMonday(new Date()); //1st date of this week
break;
case 'thismonth': var StartDate = new Date(y, m, 1); //1st date of this month
break;
case 'thisyear': var StartDate = new Date("01/01/" + date.getFullYear()); //1st date of this year
break;
case 'custom': //var StartDate = $("#txtFromDate").val();
break;
default:
var d = new Date();
var StartDate = new Date(d.getTime() - 30 * 24 * 60 * 60 * 1000); //one month ago date from now.
}
if (DateFilter != "custom") {
var SDate = $.datepicker.formatDate('#Config.DateFormat', StartDate); $("#txtFromDate").val(SDate);
var EDate = $.datepicker.formatDate('#Config.DateFormat', EndDate); $("#txtToDate").val(EDate);
}
//-----------Date Configuration march 18,2014----------------------
var curDate = new Date().toLocaleString().split(',')[0];
Simply! in dd.mm.yyyy format.
Date.prototype.NextDay = function (e) {
return new Date(this.getFullYear(), this.getMonth(), this.getDate() + ("string" == typeof e ? parseInt(e, 10) : e));
}
// tomorrow
console.log(new Date().NextDay(1))
// day after tomorrow
console.log(new Date().NextDay(2))
How can I convert this one to 12 Hour Format?
Sun Dec 31 14:45:42 GMT+07:36 1899
like this (Ex.)
2:00 PM
If you're looking for an answer that is specific to Google Apps Script, the most simple fix I can think of is to change the way you define the formatting. Based on the title of this ticket I assume you're using this:
var date = new Date("Sun Dec 31 14:45:42 GMT+07:00 1899");
var date_24hr = Utilities.formatDate(date, 'GMT+7:00', 'EEE MMM dd HH:mm:ss zXX yyyy');
// logs Sun Dec 31 14:45:42 GMT+07:00 1899
var date_12hr = Utilities.formatDate(date, 'GMT+7:00', 'EEE MMM dd h:mm:ss a zXX yyyy');
// logs Sun Dec 31 02:45:42 PM GMT+07:00 1899
var time_12hr = Utilities.formatDate(date, 'GMT+7:00', 'h:mm a');
// logs 02:45 PM
The key is to use lowercase h instead of capital H in the formatDate value.
var date=new Date();
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
formatAMPM(date);
As you've tagged this as a GAS question, have you looked at Utilities.formatDate()? Documentation here, but in short it takes 3 parameters: a date object, a time-zone string & a format string. The TZ & format are taken from the Java SE SimpleDateFormat class.
In your instance, try this:
var d = new Date("Sun Dec 31 14:45:42 GMT+07:36 1899");
Logger.log(Utilities.formatDate(d, "GMT+07:00", "h:mm a")); // logs 2:09 PM
I have a javascript object of date and its value is:
Thu Dec 18 2014 07:29:44 GMT+0500 (PKT)
Now I want to get the time from above data object in following format:
7:29 A.M
How can I do that using javascript code.
Please Help!!
You can do a little string addition by doing the following:
var result = "";
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var amORpm = hours > 12 ? "P.M" : "A.M";
if(hours > 12) hours -= 12;
result = hours + ":" + minutes + " " + amORpm;
console.log(result); // Will get you your desired format
This question already has answers here:
Formatting the date time with Javascript
(12 answers)
Closed 8 years ago.
I need to change a date/time from 2014-08-20 15:30:00 to look like 08/20/2014 3:30 pm
Can this be done using javascript's Date object?
Yes, you can use the native javascript Date() object and its methods.
For instance you can create a function like:
function formatDate(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return (date.getMonth()+1) + "/" + date.getDate() + "/" + date.getFullYear() + " " + strTime;
}
var d = new Date();
var e = formatDate(d);
alert(e);
And display also the am / pm and the correct time.
Remember to use getFullYear() method and not getYear() because it has been deprecated.
DEMO http://jsfiddle.net/a_incarnati/kqo10jLb/4/
Please do not reinvent the wheel. There are many open-source and COTS solutions that already exist to solve this problem.
Please take a look at the following JavaScript libraries:
Luxon: [CDN] | [Source] | [Minified]
Moment.js: [CDN] | [Source] | [Minified]
Datejs: [CDN] | [Source] | [Alpha1.zip (1.6MB)]
Demo
Update: I wrote a one-liner using Moment.js Luxon below.
const { DateTime } = luxon;
const value = DateTime
.fromFormat("2014-08-20 15:30:00", "yyyy-MM-dd HH:mm:ss")
.toFormat('MM/dd/yyyy h:mm a');
console.log(value); // 08/20/2014 3:30 PM
<script src="https://cdnjs.cloudflare.com/ajax/libs/luxon/1.26.0/luxon.min.js"></script>
Here is the original version using Moment. Since Luxon is the successor to Moment, I have included this as an alternative.
const value = moment('2014-08-20 15:30:00').format('MM/DD/YYYY h:mm a');
console.log(value); // 08/20/2014 3:30 pm
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
For the date part:(month is 0-indexed while days are 1-indexed)
var date = new Date('2014-8-20');
console.log((date.getMonth()+1) + '/' + date.getDate() + '/' + date.getFullYear());
for the time you'll want to create a function to test different situations and convert.
I don't think that can be done RELIABLY with built in methods on the native Date object. The toLocaleString method gets close, but if I am remembering correctly, it won't work correctly in IE < 10. If you are able to use a library for this task, MomentJS is a really amazing library; and it makes working with dates and times easy. Otherwise, I think you will have to write a basic function to give you the format that you are after.
function formatDate(date) {
var year = date.getFullYear(),
month = date.getMonth() + 1, // months are zero indexed
day = date.getDate(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds(),
hourFormatted = hour % 12 || 12, // hour returned in 24 hour format
minuteFormatted = minute < 10 ? "0" + minute : minute,
morning = hour < 12 ? "am" : "pm";
return month + "/" + day + "/" + year + " " + hourFormatted + ":" +
minuteFormatted + morning;
}
You can do that:
function formatAMPM(date) { // This is to display 12 hour format like you asked
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
var myDate = new Date();
var displayDate = myDate.getMonth()+ '/' +myDate.getDate()+ '/' +myDate.getFullYear()+ ' ' +formatAMPM(myDate);
console.log(displayDate);
Fiddle
This question already has answers here:
How to add days to Date?
(56 answers)
Incrementing a date in JavaScript
(19 answers)
How can I add 1 day to current date?
(10 answers)
Closed 12 months ago.
I am trying to get JavaScript to display tomorrows date in format (dd-mm-yyyy)
I have got this script which displays todays date in format (dd-mm-yyyy)
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
Displays: 25/2/2012 (todays date of this post)
But how do I get it to display tomorrows date in the same format i.e. 26/2/2012
I tried this:
var day = currentDate.getDate() + 1
However I could keep +1 and go over 31 obviously there are not >32 days in a month
Been searching for hours but seems to be no answer or solution around this?
This should fix it up real nice for you.
If you pass the Date constructor a time it will do the rest of the work.
24 hours 60 minutes 60 seconds 1000 milliseconds
var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
One thing to keep in mind is that this method will return the date exactly 24 hours from now, which can be inaccurate around daylight savings time.
Phil's answer work's anytime:
var currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);
The reason I edited my post is because I myself created a bug which came to light during DST using my old method.
The JavaScript Date class handles this for you
var d = new Date(2012, 1, 29) // month is 0-based in the Date constructor
console.log(d.toLocaleDateString())
// Wed Feb 29 2012
d.setDate(d.getDate() + 1)
console.log(d.toLocaleDateString())
// Thu Mar 01 2012
console.log(d.getDate())
// 1
Method Date.prototype.setDate() accepts even arguments outside the standard range and changes the date accordingly.
function getTomorrow() {
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1); // even 32 is acceptable
return `${tomorrow.getFullYear()}/${tomorrow.getMonth() + 1}/${tomorrow.getDate()}`;
}
Using JS only(Pure js)
Today
new Date()
//Tue Oct 06 2020 12:34:29 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0, 0))
//Tue Oct 06 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(new Date().setHours(0, 0, 0,0)).toLocaleDateString('fr-CA')
//"2020-10-06"
Tomorrow
new Date(+new Date() + 86400000);
//Wed Oct 07 2020 12:44:02 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0, 0) + 86400000);
//Wed Oct 07 2020 00:00:00 GMT+0530 (India Standard Time)
new Date(+new Date().setHours(0, 0, 0,0)+ 86400000).toLocaleDateString('fr-CA')
//"2020-10-07"
//don't forget the '+' before new Date()
Day after tomorrow
Just multiply by two ex:- 2*86400000
You can find all the locale shortcodes from https://stackoverflow.com/a/3191729/7877099
I would use the DateJS library. It can do exactly that.
http://www.datejs.com/
The do the following:
var d = new Date.today().addDays(1).toString("dd-mm-yyyy");
Date.today() - gives you today at midnight.
The below uses a combination of Roderick and Phil's answers with two extra conditionals that account for single digit months/days.
Many APIs I've worked with are picky about this, and require dates to have eight digits (eg '02022017'), instead of the 6 or 7 digits the date class is going to give you in some situations.
function nextDayDate() {
// get today's date then add one
var nextDay = new Date();
nextDay.setDate(nextDay.getDate() + 1);
var month = nextDay.getMonth() + 1;
var day = nextDay.getDate();
var year = nextDay.getFullYear();
if (month < 10) { month = "0" + month }
if (day < 10) { day = "0" + day }
return month + day + year;
}
Use cases :
Date.tomorrow() // 1 day next
Date.daysNext(1) // alternative Date.tomorrow()
Date.daysNext(2) // 2 days next.
IF "tomorrow " is not depend of today but of another Date different of Date.now(), Don't use static methods but rather you must use non-static :
i.e: Fri Dec 05 2008
var dec5_2008=new Date(Date.parse('2008/12/05'));
dec5_2008.tomorrow(); // 2008/12/06
dec5_2008.tomorrow().day // 6
dec5_2008.tomorrow().month // 12
dec5_2008.tomorrow().year //2008
dec5_2008.daysNext(1); // the same as previous
dec5_2008.daysNext(7) // next week :)
API :
Dateold=Date;function Date(e){var t=null;if(e){t=new Dateold(e)}else{t=new Dateold}t.day=t.getDate();t.month=t.getMonth()+1;t.year=t.getFullYear();return t}Date.prototype.daysNext=function(e){if(!e){e=0}return new Date(this.getTime()+24*60*60*1e3*e)};Date.prototype.daysAgo=function(e){if(!e){e=0}return Date.daysNext(-1*e)};Date.prototype.tomorrow=function(){return this.daysNext(1)};Date.prototype.yesterday=function(){return this.daysAgo(1)};Date.tomorrow=function(){return Date.daysNext(1)};Date.yesterday=function(){return Date.daysAgo(1)};Date.daysNext=function(e){if(!e){e=0}return new Date((new Date).getTime()+24*60*60*1e3*e)};Date.daysAgo=function(e){if(!e){e=0}return Date.daysNext(-1*e)}
Method 1: If you don't have problem in using other library, then this could work for you using moment.js
moment().add('days', 1).format('L');
Method 2: Using Date.js,
<script type="text/javascript" src="date.js"></script>
var tomorrow = new Date.today().addDays(1).toString("dd-mm-yyyy");
This method uses external library and not the native Date library.
As my bootstrap-datetimepicker was using moment.js and native date library, I preferred method 1. This question mentions these and some other methods.
Its really simple:
1: Create date object with today' date and time.
2: Use date object methods to retrieve day, month and full year and concatenate them using the + operator.
Sample Code:
var my_date = new Date();
var tomorrow_date = (my_date.getDate() + 1) + "-" + (my_date.getMonth() + 1) + "-" + my_date.getFullYear();
document.write(tomorrow_date);
function getMonday(d)
{
// var day = d.getDay();
var day = #Config.WeekStartOn
diff = d.getDate() - day + (day == 0 ? -6 : 0);
return new Date(d.setDate(diff));
}
The same as the original answer, but in one line:
var tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000)
The numbers stand for 24 hours 60 minutes 60 seconds 1000 milliseconds.
you can try this:
function Tomorrow(date=false) {
var givendate = (date!=false) ? new Date(date) : new Date();
givendate.setDate(givendate.getDate() + 1);
var day = givendate.getUTCDate()
var month = givendate.getUTCMonth()+1
var year = givendate.getUTCFullYear()
result ="<b>" + day + "/" + month + "/" + year + "</b>";
return result;
}
var day = Tomorrow('2020-06-30');
console.log('tomorrows1: '+Tomorrow('2020-06-30'));
console.log('tomorrows2: '+Tomorrow());
//to get date of tomorrow
let tomorrow=new Date(`${(new Date()).getFullYear()}-${(new Date()).getMonth()+1}-${(new Date()).getDate()+1}`);
//for dd-mm-yy format
tomorrow=`${tomorrow.getDate()}-${tomorrow.getMonth()+1}-${((tomorrow.getFullYear()).toString()).slice(-2)}`;
document.write(tomorrow)
//-----------Date Configuration march 18,2014----------------------
//alert(DateFilter);
var date = new Date();
y = date.getFullYear(), m = date.getMonth();
var EndDate = new Date();
switch (DateFilter) {
case 'today': var StartDate = EndDate; //todays date
break;
case 'yesterday':
var d = new Date();
var previousDate = new Date(d.getTime() - 1000 * 60 * 60 * 24);
var StartDate = new Date(previousDate.yyyymmdd()); //yesterday Date
break;
case 'tomorrow':
var d = new Date();
var NextDate = new Date(d.getTime() + 1000 * 60 * 60 * 24);
var StartDate = new Date(NextDate.yyyymmdd()); //tomorrow Date
break;
case 'thisweek': var StartDate = getMonday(new Date()); //1st date of this week
break;
case 'thismonth': var StartDate = new Date(y, m, 1); //1st date of this month
break;
case 'thisyear': var StartDate = new Date("01/01/" + date.getFullYear()); //1st date of this year
break;
case 'custom': //var StartDate = $("#txtFromDate").val();
break;
default:
var d = new Date();
var StartDate = new Date(d.getTime() - 30 * 24 * 60 * 60 * 1000); //one month ago date from now.
}
if (DateFilter != "custom") {
var SDate = $.datepicker.formatDate('#Config.DateFormat', StartDate); $("#txtFromDate").val(SDate);
var EDate = $.datepicker.formatDate('#Config.DateFormat', EndDate); $("#txtToDate").val(EDate);
}
//-----------Date Configuration march 18,2014----------------------
var curDate = new Date().toLocaleString().split(',')[0];
Simply! in dd.mm.yyyy format.
Date.prototype.NextDay = function (e) {
return new Date(this.getFullYear(), this.getMonth(), this.getDate() + ("string" == typeof e ? parseInt(e, 10) : e));
}
// tomorrow
console.log(new Date().NextDay(1))
// day after tomorrow
console.log(new Date().NextDay(2))