Skip to content

Instantly share code, notes, and snippets.

@MontealegreLuis
Created June 20, 2013 20:20
Show Gist options
  • Save MontealegreLuis/5826243 to your computer and use it in GitHub Desktop.
Save MontealegreLuis/5826243 to your computer and use it in GitHub Desktop.
Difference in hours between two dates.
<?php
$now = new DateTime('now', new DateTimeZone('America/Mexico_City'));
$twoHoursAgo = clone $now;
$twoHoursAgo = $twoHoursAgo->sub(new DateInterval('PT2H'));
$diff = $now->diff($twoHoursAgo);
echo $diff->format("%H hours\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment