tags:

views:

62

answers:

2

Hi

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 work. 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

+5  A: 

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'
James McNellis
tried, didnt work, expire field is still current date
Ahmet vardar
Is `date_joined` a field of `date` or `datetime` type?
James McNellis
it is date type
Ahmet vardar
Add to your question your updated code and the results you are getting.
James McNellis
this time, expire field is 0000-00-00 :S
Ahmet vardar
What is the value of `date_joined` in that row? Is it null?
James McNellis
omg ok it works now, i should have used ` instead 'thx again
Ahmet vardar
You're welcome; I'm glad we solved your problem. You don't need to use any quotes around that identifier. You only need to use backticks when your field names are keywords or you have special characters in your table name.
James McNellis
+2  A: 

You will need an update statement.

UPDATE `set` SET expire = DATE_ADD(date_joined, INTERVAL 30 DAY)
WHERE ID='$idno'
Tom
thx, tried, but expire field is 0000-00-00 now
Ahmet vardar
The single quotes around `date_joined` need to be backticks.
James McNellis
+1 because you posted this before I edited my answer (sorry about that).
James McNellis
Thanks, and +1 to you for picking up the problem with back ticks.
Tom