Jump to content

[SOLVED] Help Inserting a Future Date


limitphp

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.