Page 1 of 1

due and passed date script

Posted: Tue Jun 02, 2009 8:00 am
by diasje
Hello, i have a script, were i put some dates, like date of creation and date of update.

I need some help with some piece of script.


The script saves this values in MySql DB:
Fields:
date_creation
date_update

Fields required:
date_due
date_passed

Where should I save the number of days that passed from date_creation and date_update.

For example, I insert some data on day 02-06-2009, and 3 days later, the new field (date_due and date_passed) should show the number 3.

Then when i update the date on field date_update, the date_due field should reset to 0.

2 or more days later, this field (date_due) should show the number of days that passed since the update.

You can see my script here: http://diasje.07x.net/dreports/d_reports_list.php

Is it possible for someone to help me?


Thanks in advance, and sorry for my poor english.

Re: due and passed date script

Posted: Tue Jun 02, 2009 12:46 pm
by requinix
Don't store that kind of data - it changes too often to make it worthwhile.

Make your PHP determine how many days it's been.

Re: due and passed date script

Posted: Tue Jun 02, 2009 2:07 pm
by mikemike
I agree, you shouldn't be storing dates like that, it's pointless. Use PHP to calculate the values on-the-fly.

Re: due and passed date script

Posted: Tue Jun 02, 2009 5:29 pm
by diasje
OK thanks and how is it done?

Re: due and passed date script

Posted: Tue Jun 02, 2009 6:33 pm
by mikemike
Well if you want to find how many days it is between two dates then it's simple maths:

Code: Select all

$daysecs = 86400; // 1 day in seconds
$days = $futuretime - time(); // Calculate difference in seconds
$days = $days / $daysecs; // Exact number of days
$days = $round($days); // Round up/down and remove decimal