Forum Moderators: coopster

Message Too Old, No Replies

Using mktime with a datestamp

mktime datestamp

         

techtheatre

3:15 am on Mar 30, 2009 (gmt 0)

10+ Year Member



I am trying to make a page display the number of days remaining between today and a date that is stored in a variable ($CountDate). I found the following code online:

<?php
$cdate = mktime(0, 0, 0, 12, 31, 2009, 0);
$today = time();
$difference = $cdate - $today;
if ($difference < 0) { $difference = 0; }
echo "There are ". floor($difference/60/60/24)." days remaining";
?>

This seems to work great if I could hard-code each part of my date into the mktime function, but in my situation I have a date stored in YYYY-MM-DD format in a variable called $CountDate. Is there a way to convert a date format into something that will work as an input to mktime()? Is there some other way to calculate the number of days remaining?

Jsyvanne

12:28 pm on Mar 30, 2009 (gmt 0)

10+ Year Member



$cdate = strtotime($CountDate);

..should work :P

techtheatre

1:05 pm on Mar 30, 2009 (gmt 0)

10+ Year Member



Great! It works perfectly. Thanks so much for your help!