Tuesday, October 7, 2025
HomeLanguagesPHP | IntlCalendar setFirstDayOfWeek() Function

PHP | IntlCalendar setFirstDayOfWeek() Function

The IntlCalendar::setFirstDayOfWeek() function is an inbuilt function in PHP which is used to set the day on which the week is to be started. This function affects the behaviors of fields that depend on the week such as IntlCalendar::FIELD_WEEK_OF_YEAR and IntlCalendar::FIELD_YEAR_WOY.

Syntax:

  • Object oriented style
    bool IntlCalendar::setFirstDayOfWeek( int $dayOfWeek )
  • Procedural style
    bool intlcal_set_first_day_of_week( IntlCalendar $cal, int $dayOfWeek )

Parameters: This function uses two parameters as mentioned above and described below:

  • $cal: This parameter holds the resource of IntlCalendar object.
  • $dayOfWeek: This parameter holds one of the field constants such as IntlCalendar::DOW_SUNDAY, IntlCalendar::DOW_MONDAY, …, IntlCalendar::DOW_SATURDAY.

Return Value: This function returns True on success and False in case of invalid parameters.

Below program illustrates the IntlCalendar::setFirstDayOfWeek() function in PHP:

Program:




<?php
  
// Set the DateTime zone
ini_set('date.timezone', 'Asia/Calcutta');
ini_set('intl.default_locale', 'es_ES');
  
// Create an instance of IntlCalendar
$calendar = IntlCalendar::createInstance('Asia/Calcutta');
  
// Set the DateTime to the calendar object
$calendar->set(2019, 8, 25);
  
// Get first day of the week
var_dump($calendar->getFirstDayOfWeek());
  
// Set first day of the week
$calendar->setFirstDayOfWeek(IntlCalendar::DOW_SUNDAY);
  
// Get first day of the week
var_dump($calendar->getFirstDayOfWeek());
  
?>


Output:

int(2)
int(1)

Reference: https://www.php.net/manual/en/intlcalendar.setfirstdayofweek.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32340 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6708 POSTS0 COMMENTS
Nicole Veronica
11872 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6829 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6780 POSTS0 COMMENTS
Umr Jansen
6784 POSTS0 COMMENTS