Skip to content

Instantly share code, notes, and snippets.

@knoonrx
Last active April 19, 2016 00:00
Show Gist options
  • Save knoonrx/2b800b752a9ba01f7c8af6d663cd4069 to your computer and use it in GitHub Desktop.
Save knoonrx/2b800b752a9ba01f7c8af6d663cd4069 to your computer and use it in GitHub Desktop.
<?php
$date_expire = '2016-04-16';
$date = new DateTime($date_expire);
$now = new DateTime();
//echo $date->diff($now)->format("%d days, %h hours and %i minuts");
//$time = $date->diff($now)->format("%d");
//echo $time;
if ( $date->diff($now)->format("%d") >= 2) // if date in days is greather than 2, do something
{
echo "É maior que dois!!";
}
echo "\n";
// agora com um pouco mais de precisão
$date_expire = '2016-04-16 23:58:00';
$date = new DateTime($date_expire);
$now = new DateTime();
//echo $date->diff($now)->format("%d days, %h hours and %i minuts");
if ( $date->diff($now)->format("%d.%h") >= 2)
{
echo "É maior que dois!!";
} else {
echo "não é maior";
}
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment