Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm puzzled as to why the behaviour of %G would be desirable. Can anyone offer an example?


It is used to get the year, which a week number belongs to. The current week number (1) belongs to 2015, even though it's 2014. Here, check out this calendar [0]. We are already in week 1 of year 2015. That's why you get the year 2015.

Why is it useful you might ask: when you order a time-series by week number, or if you are grouping by week numbers, you would need the week number of course. But if the data is spanning over two years, you would need also the year for grouping, because you would add up weeks from different years. If you use week number + current year you get errors around the end of some years.

[0] http://www.calendar-365.com/2015-calendar.html


Note that these are international (ISO) week numbers. US-American week numbers are different, I'm told.


I image that it would be handy in some forms of accounting software. Some countries are very found of using week numbers, pretty much any government employee in Denmark uses week numbers, rather than actual dates, so you end up needing to known which year the current week belongs to, in this case 2015.


Exactly. In Germany it is very common to talk in terms of "Kalenderwoche" (calendar week). For planning, accounting, holidays...





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: