6

In most locale, the first day of the week is Monday. In the US (and presumably elsewhere), the week starts on Sunday.

How can find out in PHP, for an arbitrary locale, the current setting for the first day of the week (Sunday or Monday)?

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Cedric
  • 63
  • 1
  • 3

2 Answers2

13

From CLDR's supplemental data (release 36, October 2019):

<firstDay day="mon" territories="001 AD AI AL AM AN AR AT AX AZ BA BE BG BM BN BY CH CL CM CR CY CZ DE DK EC EE ES FI FJ FO FR GB GE GF GP GR HR HU IE IS IT KG KZ LB LI LK LT LU LV MC MD ME MK MN MQ MY NL NO NZ PL RE RO RS RU SE SI SK SM TJ TM TR UA UY UZ VA VN XK"/>
<firstDay day="fri" territories="MV"/>
<firstDay day="sat" territories="AE AF BH DJ DZ EG IQ IR JO KW LY OM QA SD SY"/>
<firstDay day="sun" territories="AG AS AU BD BR BS BT BW BZ CA CN CO DM DO ET GT GU HK HN ID IL IN JM JP KE KH KR LA MH MM MO MT MX MZ NI NP PA PE PH PK PR PT PY SA SG SV TH TT TW UM US VE VI WS YE ZA ZW"/>

<firstDay day="sun" territories="GB" alt="variant" references="Shorter Oxford Dictionary (5th edition, 2002)"/>

(territory 001 is the UN M49 area code for "World")

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
Jaka Jančar
  • 11,386
  • 9
  • 53
  • 74
  • I think this data isn't entirely accurate. For example the [Standard Korean Language Dictionary](https://en.wikipedia.org/wiki/Standard_Korean_Language_Dictionary) defines Monday ([월요일](https://stdict.korean.go.kr/search/searchView.do?word_no=254347&searchKeywordTo=3)) as "the day on which a week begins." but here `KR` is listed as `sun`. – Boris Verkhovskiy Jan 20 '20 at 10:30
4

Run this command in the shell (bash or sh or etc):

locale first_weekday

In PHP, call a process to run this command in sh, and get it's output. In Python, I does a thing like this:

def getLocaleFirstWeekDay():
  return int(os.popen('locale first_weekday').read())-1
  • PHP should work with `intlcal_get_first_day_of_week(intlcal_create_instance())`, too which does not require forking an another process. However, see https://bugs.php.net/bug.php?id=76073 – Mikko Rantalainen Mar 09 '18 at 12:45