bullbreed Posted January 20, 2010 Share Posted January 20, 2010 I am trying to get the date to show on my page in a particular way. I have a database Table called 'actions' set up like this; Field------------ Type------- Collation-------Attributes------Null--- Default date------------ timestamp------------------------------------------No-----CURRENT_TIMESTAMP My code that requests the time is; $date = time(); I insert it in to the database like this; $queryreg = mysql_query("INSERT INTO " . TBL_ACTION . " ( `date`) VALUES ('$date')"); I call the date to the page like this <?php echo $data['date']; ?> But this shows the date on my page like this Thu 1st January 1970 12.00AM What am I doing wrong?> I want it in this format but with the current data and time Quote Link to comment https://forums.phpfreaks.com/topic/189100-date-issues/ Share on other sites More sharing options...
MadTechie Posted January 20, 2010 Share Posted January 20, 2010 The default is 'CURRENT_TIMESTAMP' so you don't need to pass a value, but if you want to pass it, you need to format it to MySQL time $date = date('Y-m-d H:i:s',time()); OR for default $queryreg = mysql_query("INSERT INTO " . TBL_ACTION . " ( `date`) VALUES (null)") Quote Link to comment https://forums.phpfreaks.com/topic/189100-date-issues/#findComment-998360 Share on other sites More sharing options...
p2grace Posted January 20, 2010 Share Posted January 20, 2010 Also, as MadTechie mentioned you don't need to specify the date since it's automatic, however in the situation when it isn't, you can use the mysql NOW() function instead of specifying the date from a php variable. Check out php.net info on date() for more info on format strings. http://us3.php.net/manual/en/function.date.php Quote Link to comment https://forums.phpfreaks.com/topic/189100-date-issues/#findComment-998361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.