Jump to content

Recommended Posts

[!--quoteo(post=362432:date=Apr 6 2006, 11:30 PM:name=ChambeRFienD)--][div class=\'quotetop\']QUOTE(ChambeRFienD @ Apr 6 2006, 11:30 PM) [snapback]362432[/snapback][/div][div class=\'quotemain\'][!--quotec--]
How would I go about finding the difference between a date stored in the 'DATE' type in a MySQL database and the current date.. Just looking for how many days there are between the current date and what is stored in the database.
[/quote]

is it in timestamp?

try this:

// mysql timestamp from db
$old_timestamp = $row['date'];


// Time in seconds from then to right now
$elapsed_seconds = time() - $old_timestamp;

// divide by 60 for minutes, 60 for hours, then 24 for days, using floor to make an integer
$elapsed_days = floor(($elapsed_seconds / 60) / 60 / 24);
[quote]
DATEDIFF(expr,expr2)

DATEDIFF() returns the number of days between the start date expr and the end date expr2. expr and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

mysql> SELECT DATEDIFF('1997-12-31 23:59:59','1997-12-30');
-> 1
mysql> SELECT DATEDIFF('1997-11-30 23:59:59','1997-12-31');
-> -31

DATEDIFF() was added in MySQL 4.1.1
[/quote]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.