0
$\begingroup$

Why does

DateList[{"2018W01", {"Year", "W", "Week"}}]

return this

{2018, 12, 31, 0, 0, 0.}

By the way, it works in reverse:

DateString[{2018, 1, 1}, {"Year", "W", "Week"}]
"2018W01"

Okay, strangely if we do not specify the format of the string Mathematica knows better:

DateList["2018W01"]
{2018, 1, 1, 0, 0, 0.}

...but the performance is inconsistent and then Mathematica fails on other dates, i.e.:

DateList["2016W13"]
DateList::str: String 2016W13 cannot be interpreted as a date in format Automatic.

update 1 The documentations says that allowed data specifications include "Year", "YearShort", "Quarter", "Month", "MonthName", "Day", "DayName", "Hour", "Hour12", "AMPM", "Minute", "Second", or "Millisecond".

But still some dates work as expected if "Week" was an accepted specification:

DateList[{"2017W52", {"Year", "W", "Week"}}]
{2017, 12, 25, 0, 0, 0.`}
$\endgroup$
  • $\begingroup$ According to the documentation , "Week" is not supported. Also, your examples, "2018W01" and "2018W13" are both interpreted as {"Year", "Month"} which is why the first "worked" and the second did not (a year only has 12 months). $\endgroup$ – Carl Woll May 14 '19 at 14:26
  • $\begingroup$ okay, but DateList[{"2017W52", {"Year", "W", "Week"}}] returns {2017, 12, 25, 0, 0, 0.`}, which is correct, no? $\endgroup$ – iav May 14 '19 at 14:28
  • 1
    $\begingroup$ Write to support and ask for support for "Week", mentioning that it already works for every week but 1, even 0 and -1. $\endgroup$ – Carl Woll May 14 '19 at 15:18
  • $\begingroup$ Thanks, will do! $\endgroup$ – iav May 14 '19 at 16:57

Your Answer

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

Browse other questions tagged or ask your own question.