bravo14 Posted March 25, 2011 Share Posted March 25, 2011 Hi I am trying to add a field to a database that is 4 days from the date the record is added, but it is not adding a value $end_date=strtotime("+ 4 days"); $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','$end_date')") or die(mysql_error()); What am I doing wrong and what is there a better way to achieve the desired result. Link to comment https://forums.phpfreaks.com/topic/231730-add-4-days-to-today/ Share on other sites More sharing options...
nethnet Posted March 26, 2011 Share Posted March 26, 2011 The strtotime() function is notoriously strict on the input you can give it. I'm not particularly well versed in its acceptable syntax, but I would guess that you cannot have any whitespace between the plus sign and the integer when marking it 4 days from now. Link to comment https://forums.phpfreaks.com/topic/231730-add-4-days-to-today/#findComment-1192365 Share on other sites More sharing options...
Pikachu2000 Posted March 26, 2011 Share Posted March 26, 2011 Probably faster to do it in the query string with MySQL's DATE_ADD() function anyhow. INSERT INTO table (name, date_plus_four, email) VALUES ( '$name', DATE_ADD(CURDATE(), INTERVAL 4 DAY), '$email' ) Link to comment https://forums.phpfreaks.com/topic/231730-add-4-days-to-today/#findComment-1192437 Share on other sites More sharing options...
salathe Posted March 26, 2011 Share Posted March 26, 2011 Hi I am trying to add a field to a database that is 4 days from the date the record is added, but it is not adding a value What am I doing wrong and what is there a better way to achieve the desired result. What is the column type of your end_date column? Remember that you're giving it a Unix timestamp (an integer, the number of seconds since 1 Jan 1970) and that may well be different from what MySQL expects. The strtotime() function is notoriously strict on the input you can give it. I'm not particularly well versed in its acceptable syntax, but I would guess that you cannot have any whitespace between the plus sign and the integer when marking it 4 days from now. The date/time formats are well documented (though can be a lot to digest, and lack version changes/information). Link to comment https://forums.phpfreaks.com/topic/231730-add-4-days-to-today/#findComment-1192589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.