PHP | IntlDateFormatter getDateType() Function

The IntlDateFormatter::getDateType() function is an inbuilt function in PHP which is used to get the datetype used for the IntlDateFormatter object.
Syntax:
- Object oriented style:
int IntlDateFormatter::getDateType( void ) 
- Procedural style:
int datefmt_get_datetype( IntlDateFormatter $fmt ) 
Parameters: This function uses single parameter $fmt which holds the resource of formatter.
Return Value: This function returns the current date type value of the formatter.
Below programs illustrate the IntlDateFormatter::getDateType() function in PHP:
Program 1:
| <?php  // Create a date formatter $formatter= datefmt_create(     'en_US',     IntlDateFormatter::FULL,     IntlDateFormatter::FULL,     'Asia/Kolkata',     IntlDateFormatter::TRADITIONAL,     "MM/dd/yyyy");  // Get the date/type formatter type echo'Calendar of formatter: '        . datefmt_get_datetype($formatter) . "\n";   // Get the format of date/time value as a string echo"Formatted calendar output: "        . datefmt_format( $formatter, 0) . "\n\n";  // Create a date formatter $formatter= datefmt_create(     'en_US',     IntlDateFormatter::SHORT,     IntlDateFormatter::SHORT,     'Asia/Kolkata',     IntlDateFormatter::TRADITIONAL );  // Get the date/type formatter type echo'Calendar of formatter: '        . datefmt_get_datetype($formatter) . "\n";   // Get the format of date/time value as a string echo"Formatted calendar output: "        . datefmt_format( $formatter, 0);  ?>  | 
Output:
Calendar of formatter: 0 Formatted calendar output: 01/01/1970 Calendar of formatter: 3 Formatted calendar output: 1/1/70, 5:30 AM
Program 2:
| <?php  // Create a date formatter $formatter= datefmt_create(     'en_US',     IntlDateFormatter::FULL,     IntlDateFormatter::FULL,     'Asia/Kolkata',     IntlDateFormatter::TRADITIONAL,     "MM/dd/yyyy");  // Get the date/type formatter type echo'Calendar of formatter: '        . $formatter->getDateType() . "\n";   // Get the format of date/time // value as a string echo"Formatted calendar output: "        . $formatter->format(0) . "\n\n";  // Create a date formatter $formatter= datefmt_create(     'en_US',     IntlDateFormatter::SHORT,     IntlDateFormatter::SHORT,     'Asia/Kolkata',     IntlDateFormatter::TRADITIONAL );  // Get the date/type formatter type echo'Calendar of formatter: '        . $formatter->getDateType() . "\n";   // Get the format of date/time // value as a string echo"Formatted calendar output: "        . $formatter->format(0);  ?>  | 
Output:
Calendar of formatter: 0 Formatted calendar output: 01/01/1970 Calendar of formatter: 3 Formatted calendar output: 1/1/70, 5:30 AM
Reference: https://www.php.net/manual/en/intldateformatter.getdatetype.php
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek 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!
 
				 
					


