This file contains hidden or 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
// My Birthday :) | |
$date_1 = new DateTime( '1989-06-15' ); | |
// Todays date | |
$date_2 = new DateTime( date( 'Y-m-d' ) ); | |
$difference = $date_2->diff( $date_1 ); | |
// Echo the as string to display in browser for testing | |
echo (string)$difference->y; |
This file contains hidden or 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
<?php | |
function dateDiff($start, $end) { | |
$start_ts = strtotime($start); | |
$end_ts = strtotime($end); | |
$diff = $end_ts - $start_ts; | |
return round($diff / 86400); | |
} |
This file contains hidden or 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
#!/usr/bin/env php | |
# This function prints the difference between two php datetime objects | |
# in a more human readable form | |
# inputs should be like strtotime($date) | |
# Adapted from https://gist.github.com/207624 python version | |
function humanizeDateDiffference($now,$otherDate=null,$offset=null){ | |
if($otherDate != null){ | |
$offset = $now - $otherDate; | |
} |
This file contains hidden or 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
<?php | |
print time(); | |
//1324402770 | |
$unixTime = time(); | |
print_r(getdate($unixTime)); | |
// Array | |
// ( | |
// [seconds] => 48 | |
// [minutes] => 54 | |
// [hours] => 12 |
This file contains hidden or 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
<?php | |
/** | |
* time_elapsed_string() | |
* | |
* Zachary Johnson | |
* http://www.zachstronaut.com/posts/2009/01/20/php-relative-date-time-string.html | |
*/ | |
function time_elapsed_string($ptime) { | |
$etime = time() - $ptime; | |
This file contains hidden or 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
<?php | |
/** | |
* Get the relative time between two timestamps. | |
* | |
* @access public | |
* @param integer|string $time The date or timestamp that represents the time we're comparing to. | |
* @param integer|string $comparison_time [optional] The date or timestamp we want comparisons to be relative to. Defaults to the current timestamp. | |
* @param boolean $return_array [optional] Whether to return the relative time as an array of components rather than a string. Default value is FALSE. | |
* @return string Returns the amount of time between the two timestamps as a string or an array if $return_array is TRUE. |
This file contains hidden or 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
<?php | |
/** | |
* Get ISO-8601 week number for a given date | |
* | |
* @author Faisalman <[email protected]> | |
* @link http://gist.github.com/faisalman | |
* @link http://en.wikipedia.org/wiki/ISO_week_date | |
* @param $y int year | |
* @param $m int month | |
* @param $d int day |
NewerOlder