Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating two weeks forward form a day, using a marker day

I am trying to code the date of the Thursday which falls two weeks after a given date. It is more complex than just adding 14 days to a given date.

This is because if the first Wednesday after a given date week is the start date, two weeks after it, counting by Thursdays, is more then 14 days where the Thursday of week in which the date was declared is skipped.

I am thinking that it should be a JavaScript function that uses

// variable will hold the current date var today = new Date();

// variable will hold the number of the day (e.g. Wednesday = 3). var thisDay = today.getDay();

and then I will place it into the "thisDate" variable in an if statement.

Just to be clear, I am trying to use this code in a manner where the starting date is a variable which is given. I then calculate the 2 weeks after, skipping the week which the date was declared.

like image 425
joe 222 Avatar asked Nov 18 '15 18:11

joe 222


People also ask

How to get the weeks and days between any two dates?

To get the weeks and days between any two given dates, please use the below formula: 1. Enter or copy the following formula into a blank cell: Note: In this formula, A2 is the start date, and B2 is the end date.

How do you calculate the day of the week?

There are many different algorithms for calculating the day of the week. One of these is referred to as the Doomsday rule, an algorithm developed by John Conway that, with practice, can be done mentally. The algorithm is based on "doomsdays," which are specific dates that all fall on a certain day of the week in a given year.

How does the algorithm determine the date of the week?

The algorithm is based on "doomsdays," which are specific dates that all fall on a certain day of the week in a given year. These dates are the same for every year, but the day they all fall on changes with each year.

How to calculate a future date based on a given date?

Calculate a future date based on a given date with a powerful feature. 1 Select Add option from the Type section; 2 Then click to select a cell that you want to calculate a future date based on; 3 At last, enter the numbers of years, months, weeks or days that you want to add for the given date.


1 Answers

using moment.js you can do it this way:

moment().add(2, 'weeks').startOf('isoweek').add(3, 'days');

demo http://jsfiddle.net/n20vncp0/

like image 84
InTry Avatar answered Sep 19 '22 13:09

InTry