Reputation: 700
i use WordPress to build a site.i need to get an alert to my web site profile page when a registration date is near.i use an available database to get the date and its saved as a string.and i check it with current date this is the code i tried. my problem is the format is not converted to the date still when i var_dump it.any help would be great!
global $wpdb;
$id=(int)$user_ID;
$FinalDay = $wpdb->get_var( "my query" );//this works!
//$Final day is the string i try to convert
$FinalDay= date('Y-m-d H:i:s', strtotime($FinalDay));
$now = new DateTime();
echo var_dump($FinalDay);//but it gives me a string formated one!
$interval = $now->diff($FinalDay);
if ( $FinalDay > $now ) {
echo "<p>Expiry date is {$FinalDay}</p>";
echo $interval->format('%R%a days');
}
else {
echo 'Licence Expired';
}
Upvotes: 0
Views: 232
Reputation: 1568
Try to use DateTime class.
Change
$FinalDay= date('Y-m-d H:i:s', strtotime($FinalDay));
With
$FinalDay= DateTime::createFromFormat('Y-m-d H:i:s', $FinalDay);
$FinalDay should be in format 'Y-m-d H:i:s'.
Upvotes: 2