On Mathematica 10.0.1 both

DayRound[{1980, 2, 29}, "EndOfMonth", "Preceding"]


DayRound[{1980, 2, 29}, "EndOfMonth", "Following"]



Is that correct? I would expect that the first one would produce the January 31 and the later one to produce March 31.


This is documented behavior. From the docs on DayRound >> Details and Options:

In DayRound[date, daytype, rounding]

If date is of daytype, DayRound has no effect.

So, since {1980, 2, 29} an "EndOfMonth" day, its "rounded" form is itself. And

DayRound[{1980, 2, 28}, "EndOfMonth","Preceding"]

return DateObject[{1980, 1, 31}, CalendarType -> "Gregorian"] as expected. However, you need

DayRound[{1980, 3, 1}, "EndOfMonth","Following"]

to get DateObject[{1980, 3, 31}, CalendarType -> "Gregorian"].

  • $\begingroup$ thanks. Yet I still struggle to understand the logic of "Preceding" and "Following" having no effect. $\endgroup$ – iav Nov 9 '14 at 18:29
  • 1
    $\begingroup$ @iav, i agree it does feel puzzling. Perhaps it helps to try to think of "Preceding" and "Following" in the weak inequality (LessEqual and GreaterEqual) sense. $\endgroup$ – kglr Nov 9 '14 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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