I really need your help with this,
What I would like to accomplish is being able to return the date value ( the day name ) after two weeks starting from today, in this example it's gonna be Friday.
var present_date = Thursday, November 23, 2017
var result_date = Friday, December 8, 2017 // after two weeks
function present_date_plus_2weeks() {
var now = new Date()
now.setDate(now.getDate()+14)
alert(now)
}
It gets the date 2 weeks from the present date, but I need the code to get the Friday (the day name)
Impossible to do?
Based on your code and what i understand from it:
var present_date = new Date();
var days = ['Monday', 'tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
function present_date_plus_2weeks() {
var now = new Date()
now.setDate(now.getDate()+14)
var numDay = now.getDay();
alert(days[numDay]);
}
present_date_plus_2weeks();
However, i would recommend using momentjs
with that you can simply do :
var afterTwoWeeks = new moment().add(14, 'days').format('dddd');
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments