PHP Calendar and Date functions Functions
These functions are used to get dates and times, as well as information about calendars
-
<?php
$date=getdate();
echo "The time is $date[hours]:$date[minutes]:$date[seconds], $date[weekday], $date[month] $date[mday], $date[year]";
//Returns
The time is 9:27:19, Thursday, July 18, 2013
?>
<?php
echo $formatted=date("h:i:s: A, D d, F, Y"); //Hours(leading zero):minutes(leading zeros):seconds(leading zeros), AM/PM, Day of week, Day of month, Month, year
//Returns:
09:27:19: AM, Thu, 18, July, 2013
?>
- mktime takes a time and returns a unix timestamp
int mktime([int $hour], [int $minute], [int $second], [int $month], [int $day], [int $year], [int $daylight_savings])
Parameters:
- int $hour: Optional. Default the current hour. The number of hours since the start of the day
- int $minute: Optional. Default the current minute. The number of minutes since the start of the hour.
- int $second: Optional. Default the current second. The number of seconds since the start of the minute
- int $month: Optional. Default the current month.
- int $day: Optional. The day of week
- int $year: Optional. The year
- int $daylight_savings: Optional. If daylight savings time is on
Return values:
- Returns the Unix Timestamp
Examples:
<?php
echo $time=date("h:i:s: A, D, d, F, Y", mktime(9,14,54,7,14,2013));
//Returns
09:14:54: AM, Sun, 14, July, 2013
?>
<?php
echo cal_days_in_month(CAL_GREGORIAN,2,2012); //Leap year
//Returns:
29
?>