Jump to content

Add a fixed number of days to today


bravo14

Recommended Posts

Hi Guys

 

I am trying to populate a field in a database with a the date 4 days from 'today'.

 

I have used the query below, but I am getting an error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATE_ADD(NOW(), INTERVAL 4 DAY))' at line 2

 

$add_vehicle_sql=mysql_query("INSERT INTO `tbl_auction_lot`(`cust_id`,`reserve`,`make`,`model`,`spec`,`fuel`,`doors`,`mot_date`,`fns`,`fos`,`rns`,`ros`,`condition`,`reg_no`,`service_history`,`sale_type`,`status`,`keepers`,`gearbox`,`emissions`,`colour`,`date_first_reg`,`date_manufacture`,`bhp`,`engine_size`,`end_date`)
VALUES ('$seller_id','$reserve','$make','$model','$body_style','$fuel_type','$no_of_doors','$mot','$fns','$fos','$rns','$ros','$vehicle_condition','$vrm','$service_history','auction','$status','$prev_keepers','$gearbox','$emissions','$colour','$date_reg','$date_man','$bhp','$engine_size',DATE_ADD(NOW(), INTERVAL 4 DAY))")

How would I do this?

Link to comment
Share on other sites

Maybe do something like this: 

<?php
$four_days = mktime(0, 0, 0, date("m"), date("d")+4, date("y"));
echo "4 days from now is ".date("m/d/y", $four_days); 
?>

 

Of course in your example you'd use the value to be entered into the database.

 

 

Link to comment
Share on other sites

Your query looks correct. I suspect there is something in one of the values that is breaking the sql syntax and the error is just detected at that point.

 

I recommend that you form your sql query in a php variable and then echo that variable so that you can see what exactly the sql is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.