Skip to content

Instantly share code, notes, and snippets.

@akritiko
Last active August 29, 2015 14:00
Show Gist options
  • Save akritiko/11250683 to your computer and use it in GitHub Desktop.
Save akritiko/11250683 to your computer and use it in GitHub Desktop.
Time travel (PHP)
/**
* Time Travel returns dates in the past or the future, to a specific format, based on a seed date.
*
* @param $date_format the format of dates (seed and returned)
* @param $date the seed date
* @param $where_to time travel "step" in days (e.g. for yesterday "-1", tomorrow "+1" and so forth)
*/
function time_travel( $date_format, $date, $where_to ) {
return date( $date_format, strtotime( $date . ' ' . $where_to . ' day' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment