How to group by week in MySQL?

You can use both YEAR(timestamp) and WEEK(timestamp), and use both of the these expressions in the SELECT and the GROUP BY clause. Not overly elegant, but functional… And of course you can combine these two date parts in a single expression as well, i.e. something like SELECT CONCAT(YEAR(timestamp), “https://stackoverflow.com/”, WEEK(timestamp)), etc… FROM … WHERE .. … Read more

How to get the day of week and the month of the year?

Yes, you’ll need arrays. var days = [‘Sunday’,’Monday’,’Tuesday’,’Wednesday’,’Thursday’,’Friday’,’Saturday’]; var months = [‘January’,’February’,’March’,’April’,’May’,’June’,’July’,’August’,’September’,’October’,’November’,’December’]; var day = days[ now.getDay() ]; var month = months[ now.getMonth() ]; Or you can use the date.js library. EDIT: If you’re going to use these frequently, you may want to extend Date.prototype for accessibility. (function() { var days = [‘Sunday’,’Monday’,’Tuesday’,’Wednesday’,’Thursday’,’Friday’,’Saturday’]; var months … Read more

How to find out the date of the first day of week from the week number in C++

Using Howard Hinnant’s free, open-source, header-only date library, it can look like this: #include “date.h” #include “iso_week.h” #include <iostream> int main() { using namespace iso_week::literals; std::cout << date::year_month_day{2017_y/8_w/mon} << ‘\n’; std::cout << date::year_month_day{2017_y/10_w/mon} << ‘\n’; } which outputs: 2017-02-20 2017-03-06 There are also getters for year, month and day on the year_month_day types, and plenty … Read more