Day of week: Difference between revisions
Jump to navigation
Jump to search
| (One intermediate revision by the same user not shown) | |||
| Line 43: | Line 43: | ||
| 7 | | 7 | ||
|- | |- | ||
! [https://support.office.com/zh-tw/article/WEEKDAY-%E5%87%BD%E6%95%B8-60e44483-2ed1-439f-8bd0-e404c190949a Excel WEEKDAY() function] | ! [https://support.office.com/zh-tw/article/WEEKDAY-%E5%87%BD%E6%95%B8-60e44483-2ed1-439f-8bd0-e404c190949a Excel WEEKDAY() function] e.g. WEEKDAY(A2) or WEEKDAY(A2, 1) | ||
| 1 | | 1 | ||
| 2 | | 2 | ||
| Line 51: | Line 51: | ||
| 6 | | 6 | ||
| 7 | | 7 | ||
|- | |||
! [https://support.office.com/zh-tw/article/WEEKDAY-%E5%87%BD%E6%95%B8-60e44483-2ed1-439f-8bd0-e404c190949a Excel WEEKDAY() function] e.g. WEEKDAY(A2, 2) | |||
| 7 | |||
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
|- | |- | ||
! [http://php.net/manual/en/function.date.php PHP date] with w format character | ! [http://php.net/manual/en/function.date.php PHP date] with w format character | ||
| Line 118: | Line 127: | ||
* [https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 - Wikipedia] | * [https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 - Wikipedia] | ||
* [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.office.com/zh-tw/article/today-%E5%87%BD%E6%95%B8-5eb3078d-a82c-4736-8930-2f51a028fdd9 TODAY 函數 - Office 支援] | * [https://support.office.com/zh-tw/article/today-%E5%87%BD%E6%95%B8-5eb3078d-a82c-4736-8930-2f51a028fdd9 TODAY 函數 - Office 支援] | ||
* [https://errerrors.blogspot.com/2026/06/spreadsheet-weekday-formula.html 在 Google 試算表、Excel 與 LibreOffice Calc 如何顯示星期幾] | |||
[[Category:PHP]] | [[Category:PHP]] | ||
Latest revision as of 00:57, 26 June 2026
Numeric representation of the day of the week. MySQL, Excel or PHP approaches to specify these date time.
Weekday[edit]
The value of weekday obtained from different approaches.
| 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 |
| MySQL DAYOFWEEK() Function | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| Excel WEEKDAY() function e.g. WEEKDAY(A2) or WEEKDAY(A2, 1) | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| Excel WEEKDAY() function e.g. WEEKDAY(A2, 2) | 7 | 1 | 2 | 3 | 4 | 5 | 6 |
| PHP date with w format character | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Get the date[edit]
Get the date of weekday from another known date (today or another specific day)
| 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; |
MySQL: SELECT CURDATE() + INTERVAL -3 - WEEKDAY(CURDATE()) DAY; PHP: echo date('Y-m-d', strtotime('Friday -7 day')) . PHP_EOL; |
MySQL: SELECT CURDATE() + INTERVAL -2 - WEEKDAY(CURDATE()) DAY; 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 PHP: echo date('Y-m-d', strtotime('Friday')) . PHP_EOL; |
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; |
PHP: echo date('Y-m-d', strtotime('Friday +7 day')) . PHP_EOL; |
References[edit]
Further reading[edit]
- 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
- TODAY 函數 - Office 支援
- 在 Google 試算表、Excel 與 LibreOffice Calc 如何顯示星期幾