Skip to content

Instantly share code, notes, and snippets.

@itsananderson
Created June 8, 2012 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save itsananderson/2894021 to your computer and use it in GitHub Desktop.
Save itsananderson/2894021 to your computer and use it in GitHub Desktop.
Turn a time difference into a "description" (e.g. "2 days 12 hours 13 minutes")
<?php
$now = time();
$then = 12345;
$diff = $then - $now;
$days = floor( $diff / (60*60*24) );
$time = date( __( 'G \h\o\u\r\s i \m\i\n\u\t\e\s'), $diff );
$message = sprintf( __( '%d days %s' ), $days, $time );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment