views:

420

answers:

2

How do you add time or days to a current utc_timestamp?

I am using;

new CDbExpression('UTC_TIMESTAMP()')

for both 'created' and 'updated' fields in my mysql table but would like to add an 'expiry' field which would allow 4 days from creation date. I presume this is possible but am unsure how.

Thanks

A: 

for insert/update current time

UPDATE table SET created = NOW()

for 4 days from creation date SELECT * FROM table WHERE created > DATE_SUB( NOW( ), INTERVAL 4 DAY )

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

skargor
A: 

In MySQL :

ALTER TABLE `table` 
    ADD expiry datetime DEFAULT DATE_ADD( utc_timestamp( ) , INTERVAL 4 DAY);
Amadeus45