due and passed date script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
diasje
Forum Newbie
Posts: 2
Joined: Tue Jun 02, 2009 7:58 am

due and passed date script

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: due and passed date script

Post 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.
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: due and passed date script

Post by mikemike »

I agree, you shouldn't be storing dates like that, it's pointless. Use PHP to calculate the values on-the-fly.
diasje
Forum Newbie
Posts: 2
Joined: Tue Jun 02, 2009 7:58 am

Re: due and passed date script

Post by diasje »

OK thanks and how is it done?
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: due and passed date script

Post 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
Post Reply