Day of week: Difference between revisions
Jump to navigation
Jump to search
| Line 102: | Line 102: | ||
* [https://stackoverflow.com/questions/23020162/how-to-get-this-coming-sundays-date mysql - How to get this coming Sunday's date? - Stack Overflow] | * [https://stackoverflow.com/questions/23020162/how-to-get-this-coming-sundays-date mysql - How to get this coming Sunday's date? - Stack Overflow] | ||
* [https://support.microsoft.com/zh-tw/help/827327/how-to-return-a-day-of-the-week-for-a-date-in-excel 如何在 Excel 中傳回的日期星期幾] | * [https://support.microsoft.com/zh-tw/help/827327/how-to-return-a-day-of-the-week-for-a-date-in-excel 如何在 Excel 中傳回的日期星期幾] | ||
* [https://support.office.com/zh-tw/article/today-%E5%87%BD%E6%95%B8-5eb3078d-a82c-4736-8930-2f51a028fdd9 TODAY 函數 - Office 支援] | |||
[[Category:PHP]] | [[Category:PHP]] | ||
Revision as of 15:04, 25 April 2018
Numeric representation of the day of the week. MySQL, Excel or PHP approaches to specify these date time.
Weekday
| Weekday values from different approaches | Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday |
|---|---|---|---|---|---|---|---|
| PHP date with N format character: Weekday (ISO-8601) | 7 | 1 | 2 | 3 | 4 | 5 | 6 |
| MySQL Weekday function | 6 | 0 | 1 | 2 | 3 | 4 | 5 |
| Excel Weekday function | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| PHP date with w format character | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Get the date
| Day | Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday |
|---|---|---|---|---|---|---|---|
| Last week | MySQL: SELECT CURDATE() + INTERVAL -8 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())-6 PHP: echo date('Y-m-d', strtotime("Sunday -14 day")) . PHP_EOL; |
MySQL: SELECT CURDATE() + INTERVAL -7 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())-5 PHP: echo date('Y-m-d', strtotime("monday this week -7 day")) . PHP_EOL; |
PHP[1]: (1) echo date('Y-m-d', strtotime("last Saturday")) . PHP_EOL; (2) echo date('Y-m-d', strtotime('last Saturday', strtotime("2018-03-04 00:01:00"))) . PHP_EOL; | ||||
| This week | MySQL: SELECT CURDATE() + INTERVAL -1 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+1 PHP: echo date('Y-m-d', strtotime("Sunday -7 day")) . PHP_EOL; |
MySQL: SELECT CURDATE() + INTERVAL 0 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+2 PHP: echo date('Y-m-d', strtotime("monday this week")) . PHP_EOL; |
MySQL: SELECT CURDATE() + INTERVAL 1 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+3 |
MySQL: SELECT CURDATE() + INTERVAL 2 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+4 |
MySQL: SELECT CURDATE() + INTERVAL 3 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+5 |
MySQL: SELECT CURDATE() + INTERVAL 4 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+6 |
MySQL: SELECT CURDATE() + INTERVAL 5 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+7 PHP: echo date('Y-m-d', strtotime("Saturday")) . PHP_EOL; |
| Next week | MySQL: SELECT CURDATE() + INTERVAL 6 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+8 PHP: echo date('Y-m-d', strtotime("Sunday")) . PHP_EOL; |
MySQL: SELECT CURDATE() + INTERVAL 7 - WEEKDAY(CURDATE()) DAY; Excel: =TODAY()-WEEKDAY(NOW())+9 PHP: (1) echo date('Y-m-d', strtotime("next monday")) . PHP_EOL; (2) echo date('Y-m-d', strtotime("monday this week +7 day")) . PHP_EOL; |
References
Further reading
- PHP date function: w character (0 for Sunday through 6 for Saturday) or N character (1 for Monday through 7 for Sunday)
- WEEKDAY 函數 - Office 支援
- ISO 8601 - Wikipedia
- mysql - How to get this coming Sunday's date? - Stack Overflow
- 如何在 Excel 中傳回的日期星期幾
- TODAY 函數 - Office 支援