PHP | IntlCalendar fromDateTime() Function Last Updated : 25 Sep, 2019 Comments Improve Suggest changes Like Article Like Report The IntlCalendar::fromDateTime() function is an inbuilt function in PHP which is used to create an IntlCalendar from a DateTime object or string. The value of new calendar represents the same instant as the DateTime and timezone. Syntax: Object oriented style IntlCalendar IntlCalendar::fromDateTime( mixed $dateTime ) Procedural style IntlCalendar intlcal_from_date_time( mixed $dateTime ) Parameters: This function accepts single parameter $dateTime which holds the DateTime object or a string that can be passed to DateTime::__construct() function. Return Value: This function returns the IntlCalendar object on success or NULL on failure. If a string is passed as a parameter then an exception occurs inside the DateTime constructor. Below programs illustrate the IntlCalendar::fromDateTime() function in PHP: Program 1: php <?php // Create an IntlCalendar from a DateTime object or string $calendar = IntlCalendar::fromDateTime('2019-08-29 09:19:29'); // Add the date $calendar->add(IntlCalendar::FIELD_YEAR, 5); // Display the result date echo IntlDateFormatter::formatObject($calendar), "\n"; // Add the date $calendar->add(IntlCalendar::FIELD_YEAR, 10); // Display the result output echo IntlDateFormatter::formatObject($calendar), "\n"; // Add the date $calendar->add(IntlCalendar::FIELD_HOUR_OF_DAY, 10); // Display the result output echo IntlDateFormatter::formatObject($calendar); ?> Output: Aug 29, 2024, 9:19:29 AM Aug 29, 2034, 9:19:29 AM Aug 29, 2034, 7:19:29 PM Program 2: php <?php // Create an IntlCalendar from a DateTime object or string $calendar = IntlCalendar::fromDateTime('2019-08-29 09:19:29'); // Add the date $calendar->add(IntlCalendar::FIELD_MONTH, 1); // Display the result date echo IntlDateFormatter::formatObject($calendar); ?> Output: Sep 29, 2019, 9:19:29 AM Reference: https://www.php.net/manual/en/intlcalendar.fromdatetime.php Comment More infoAdvertise with us Next Article PHP | IntlCalendar fromDateTime() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Intl Similar Reads PHP | IntlCalendar after() Function The IntlCalendar::after() function is an inbuilt function in PHP which returns True if the object time is after that of the passed object. Syntax: Object oriented style:bool IntlCalendar::after( IntlCalendar $other )Procedural style:bool intlcal_after( IntlCalendar $cal, IntlCalendar $other ) Parame 1 min read PHP | IntlCalendar before() Function The IntlCalendar::before() function is an inbuilt function in PHP which returns True if the object current time is before that of the passed object. Syntax: Object oriented style: bool IntlCalendar::before( IntlCalendar $other ) Procedural style: bool intlcal_before( IntlCalendar $cal, IntlCalendar 1 min read PHP | IntlCalendar createInstance() Function The IntlCalendar::createInstance() function is an inbuilt function in PHP which is used to create an instance of IntlCalendar. Syntax: Object oriented style: IntlCalendar IntlCalendar::createInstance( mixed $timeZone = NULL, string $locale = "" ) Procedural style: IntlCalendar intlcal_create_instanc 2 min read PHP | IntlCalendar add() Function The IntlCalendar::add() function is an inbuilt function in PHP which is used to add a signed amount of time to a field. Syntax: Object oriented style: bool IntlCalendar::add( int $field, int $amount ) Procedural style: bool intlcal_add( IntlCalendar $cal, int $field, int $amount ) Parameters: $cal: 2 min read PHP | IntlCalendar::__construct() Function The IntlCalendar::__construct() function is an inbuilt function in PHP which is used to create a private constructor for disallowing instantiation. Syntax: private IntlCalendar::__construct( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return 1 min read Like