Jump to content

[SOLVED] simple date problem


acidglitter

Recommended Posts

edit:

 

I tried it with the date you gave me.

 

I never tried anything like this before, so i randomly made my own script, and seems like it worked

 

<?php
$now  = time();
$date = mktime(0,0,0,12,18,2007);

$now = explode("-",date("y-m-d",$now));
$then = explode("-",date("y-m-d",$date));

$year = $now[0] - $then[0];
$month = $now[1] - $then[1];
$days = $then [2] - $now[2]; 
echo "Years left: ".$year;
echo "<br>";
echo "Months left: ".$month;
echo "<br>";
echo "Days left: ".$days;
?>

 

 

You could also do it in SQL....

 

mysql> SELECT DATEDIFF('2007-12-25', CURDATE());

+-----------------------------------+

| DATEDIFF('2007-12-25', CURDATE()) |

+-----------------------------------+

|                                 9 |

+-----------------------------------+

1 row in set (0.00 sec)

 

 

Meaning, you could probably do something like:

 

SELECT DATEDIFF(DATE(in_the_future_column), CURDATE()) as days_until

 

 

Edit: Manual link: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_curdate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.