DATE_ADD problem
I am working to add 1 month to date() and save it in my field on database.
I use this
$query2 = "SELECT * ,DATE_ADD(`date_joined`,INTERVAL 30 DAY) AS expire FROM `set` WHERE ID='$idno'";
$result2 = mysql_query($query2);
"expire" is the field i want to save as +30 days. date_joined is current date.
but it doesn't wo开发者_如何学运维rk. expire field is still current date no error message.
what should i do?
or is there another way to add 30 days to current date and save it as my "expire" field ?
Thanks
You are missing a comma between the asterisk and the DATE_ADD
call. It should look like this:
SELECT *,
DATE_ADD(`date_joined`, INTERVAL 30 DAY) AS expire
FROM `set`
WHERE ID='$idno'
Once you fix that, the query looks well formed.
Edit: It sounds like you need an update
statement, not a select
statement. Try:
update `set`
set `expire` = date_add(`date_joined`, interval 30 day)
where `id` = '$idno'
You will need an update statement.
UPDATE `set` SET expire = DATE_ADD(date_joined, INTERVAL 30 DAY)
WHERE ID='$idno'
精彩评论