tags:

views:

766

answers:

2

I have a date in the following format

MM-DD-YYYY

How can I convert this to UNIX time in PHP

Thanks

Having a small problem

$date = strtotime($_POST['retDate']);
print $date; //Prints nothing
print $_POST['retDate']; //Prints 08-18-2009
+1  A: 

Use strtotime:

$str = "03-31-2009";
$unixtime = strtotime($str);
Doug Hays
+1  A: 

If the format is always like that, I'd would try something like:

list($m,$d,$y) = explode('-', '08-18-2009');
$time = mktime(0, 0, 0, $m, $d, $y);
print date('m-d-Y', $time);

As for your example, the problem is the function fails. You should check it like so:

if(($time=strtotime('08-18-2009'))!==false)
{
 // valid time format
}
else
 echo 'You entered an invalid time format';
Daniel
thanks, mktime did the trick
Steven1350