Created
February 7, 2014 04:07
-
-
Save ZellSnippets/8857254 to your computer and use it in GitHub Desktop.
PHP: DateTime common
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Get Year | |
$today = new DateTime(); | |
$year = $today->format('Y'); | |
// Set Date | |
$date = new DateTime(); | |
$date->setDate(2014, 12, 31); | |
// Echo date | |
echo $date->format('Y-m-d'); | |
// Get Time difference | |
$interval = $today->diff($end_of_year); | |
echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days "; | |
echo "difference " . $interval->days . " days "; | |
// Get No of days in a year | |
// set date for both start and end of year, then use the following | |
$interval = $end_of_year->diff($start_of_year); | |
$days_in_year = $interval->days + 1; | |
echo $days_in_year; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment