Skip to content

Instantly share code, notes, and snippets.

@davidcraig
Last active March 31, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcraig/dc057571b07983a5d2d833f9d09cdbfc to your computer and use it in GitHub Desktop.
Save davidcraig/dc057571b07983a5d2d833f9d09cdbfc to your computer and use it in GitHub Desktop.
PHP: Countdown to a given date
<?php
$date = ''; // Pass in your date variable here, eg $date = '2014-09-08'
$today = new DateTime();
$to = new DateTime($date);
$countdown = $today->diff($to);
// Seperate variables for days, months, years, etc.
$seconds = $countdown->s;
$days = $countdown->d;
$months = $countdown->m;
$years = $countdown->y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment