Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I, in one line, generate all the dates with a constant day difference from one date to another?

For example, if I'm interested in dates in the interval staring from 24.4.2012 till 2015 and a 28 day difference.

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

Perhaps this way:

Table[DatePlus[{2012, 4, 24}, 28*i], {i, 1, 40}]

{{2012, 5, 22}, {2012, 6, 19}, {2012, 7, 17}, {2012, 8, 14}, {2012, 9, 11}, {2012, 10, 9}, {2012, 11, 6}, {2012, 12, 4}, {2013, 1, 1}, {2013, 1, 29}, {2013, 2, 26}, {2013, 3, 26}, {2013, 4, 23}, {2013, 5, 21}, {2013, 6, 18}, {2013, 7, 16}, {2013, 8, 13}, {2013, 9, 10}, {2013, 10, 8}, {2013, 11, 5}, {2013, 12, 3}, {2013, 12, 31}, {2014, 1, 28}, {2014, 2, 25}, {2014, 3, 25}, {2014, 4, 22}, {2014, 5, 20}, {2014, 6, 17}, {2014, 7, 15}, {2014, 8, 12}, {2014, 9, 9}, {2014, 10, 7}, {2014, 11, 4}, {2014, 12, 2}, {2014, 12, 30}, {2015, 1, 27}, {2015, 2, 24}, {2015, 3, 24}, {2015, 4, 21}, {2015, 5, 19}}

Of course you might want to finetune the number of 28-day intervals.

share|improve this answer
add comment

Single liner using currently available commands and avoiding the legacy issues.

NestList[DatePlus[#, 28] &, #1, 
   Round[DateDifference[##2]/28]] & @@ {{2012, 4, 24}, {2015, 12, 31}}
share|improve this answer
add comment

You can use the built in Calendar functions :

Needs["Calendar`"]

Floor[DaysBetween[{2012, 4, 24}, {2015, 12, 31}]/28]

(* 48 *)

NestList[DaysPlus[#, 28] &, {2012, 4, 24}, 48]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.