Forum Moderators: coopster

Message Too Old, No Replies

Calculating date

         

adammc

10:16 pm on Aug 8, 2007 (gmt 0)

10+ Year Member



Hi Guys,

I am using the following to store the date when a user registers on my site and determine the date / time 12 months ahead of the registered date.

[php]
# Get the current server time
$now = time();

# Determine the expiry date '365 days'
$days2expire = 365;

# timestamp of expiry date
$expirystamp = strtotime('+' . $days2expire . ' days', $now);

# make it human readable
$expiry_date = date("Y/m/d @ H:i:s", $expirystamp); // example output 2008/08/08 @ 06:54:15
$date_registered = date("d-m-Y H:i:a", $expirystamp); // example output 08-08-2008 06:54:am

[/php]

I will need to write code to update a record in the DB to 'expired' if the expiry_date is past the current date.

Am I best to store the date in the DB like so using ($expiry_date & $date_registered)?
[php]
date_registered DATETIME NOT NULL default '0000-00-00 00:00:00',
date_12_months_ahead DATETIME NOT NULL default '0000-00-00 00:00:00',
[/php]

Or should I be using timestamps and a different type of table?

Any advice would be greatly appreciated :)

Habtom

5:40 am on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I find it much easier to store and manipulate timestamps, so I am going to go with timestamps.

SixTimesEight

9:43 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



I second the timestamp vote. It's much easier to store, retrieve and work with a ten digit integer.