limitphp Posted November 12, 2008 Share Posted November 12, 2008 I'm trying to insert a future date in the mysql database. Its not working right now. The date field is type datetime. here's the code: if ($rememberMe=="on"){ setcookie("nwo",$tempID, time()+3600*24*30); mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) VALUES ('$tempID', '$userID', NOW(),INTERVAL 30 DAY)"); }else{ setcookie("nwo",$tempID, 0); mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) VALUES ('$tempID', '$userID', NOW(),INTERVAL 20 MINUTES)"); } Is that not correct syntax for the query? Its not putting anything in the database. I'm trying to insert 30 days from now in one, and 20 minutes from now in the other statement. Link to comment https://forums.phpfreaks.com/topic/132434-solved-help-inserting-a-future-date/ Share on other sites More sharing options...
limitphp Posted November 12, 2008 Author Share Posted November 12, 2008 I tried NOW()+INTERVAL 30 DAY as well. It didn't work. Link to comment https://forums.phpfreaks.com/topic/132434-solved-help-inserting-a-future-date/#findComment-688571 Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 Check this out http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html if ($rememberMe=="on"){ setcookie("nwo",$tempID, time()+3600*24*30); mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) VALUES ('$tempID', '$userID', DATE_ADD(NOW(),INTERVAL 30 DAY))"); }else{ setcookie("nwo",$tempID, 0); mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) VALUES ('$tempID', '$userID', DATE_ADD(NOW(),INTERVAL 20 MINUTES))"); } I believe you are missing the DATE_ADD function in your query. Link to comment https://forums.phpfreaks.com/topic/132434-solved-help-inserting-a-future-date/#findComment-688575 Share on other sites More sharing options...
limitphp Posted November 12, 2008 Author Share Posted November 12, 2008 Added Date_Add and changed minutes to minute. Thank you so much! I was trying to google the answer and it was driving me crazy..... Link to comment https://forums.phpfreaks.com/topic/132434-solved-help-inserting-a-future-date/#findComment-688580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.