Re: Calculating time?
| From: | php3 at developersdesk dot com | Date: | Sun, 12 Nov 2000 11:10:57 +0000 |
| Subject: | Re: Calculating time? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24849@lists.php.net to get a copy of this message | ||
Addressed to: =?iso-8859-4?B?TGF1cmkgVuRpbg==?= <optima@hot.ee>
php-general@lists.php.net
** Reply to note from =?iso-8859-4?B?TGF1cmkgVuRpbg==?= <optima@hotee> Sat, 11 Nov 2000
19:58:23 +0200
>
> Hi there, I have to delete a database entry once 30 days (that is 2592000
> seconds) have passed. I currently have my date in the following form:
> YearMonthDayHourMinuteSecond (everything has 2 digits so there are a
> total of 12 numbers). The code to produce the numbers looks like this:
>
> $cookvaldate = date("ymdHis");
>
> Any recommendations on how I could calculate whether 30 days have passed?
> At this point in writing the code, I can still change the way how I store
> dates and time (so "yy-mm-dd hh:mm:ss" and everything else would be fine
> too).
>
> Could you please help me out? Code snippets would be highly appreciated
If it was me, the first thing I would do is change your date field into a
real DATETIME field.
ALTER TABLE tablename add NewDate DATETIME;
UPDATE tablename set NewDate = concat( '20', olddate );
ALTER TABLE tablename drop olddate, change NewDate olddate DATETIME;
Now you will get 14 characters in the form yyyymmddhhmmss, but the database
is now aware that it is a date-time value, and is able to store it more
compactly than 12 characters. It also allows for a query like this:
DELETE FROM tablename WHERE DATE_ADD( olddate INTERVAL 30 DAYS ) < NOW();
If you just can't change the field type, then write a program that can come
up with the date from 30 days ago, $DeleteDate and do this:
DELETE FROM tablename WHERE olddate < '$DeleteDate';
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com