CincoPistolero Posted February 13, 2007 Share Posted February 13, 2007 I'm trying to set a mySQL DB field lastLoginDate with the current date. Below is my code. $date = date('d.m.Y'); $update_login = $db_object->query("UPDATE users SET lastLoginDate='$date' logged_in = '1' WHERE userName = '".$_POST['uname']."'"); Nothing gets put in the DB. Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 <?php $userName=addslashes($_POST['userName']); $date=addslashes($_POST['date']); $date = date("d-m-Y"); $update_login = "UPDATE `users` SET `lastLoginDate`='$date' `logged_in` = '1' WHERE `userName` = '$userName' "; $result_insert=mysql_query($update_login); ?> Quote Link to comment Share on other sites More sharing options...
CincoPistolero Posted February 13, 2007 Author Share Posted February 13, 2007 This set my date in the DB, but set it to '2013-02-20'. Below is what I have now. $date = date('d-m-Y'); $update_login = $db_object->query("UPDATE users SET lastLoginDate='$date' WHERE userName = '".$_POST['uname']."'"); $result_insert=mysql_query($update_login); I had been missing the $result_insert line Any hints on why the date is wrong? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 13, 2007 Share Posted February 13, 2007 UPDATE table SET col=NOW() WHERE conditions Quote Link to comment Share on other sites More sharing options...
CincoPistolero Posted February 13, 2007 Author Share Posted February 13, 2007 Ok, I switched from $date = (m-d-Y); to $date =(Y-m-d) and it got the correct date. Now if I want to display it on another page in mm-dd-YYYY format, can someone point me to how to do that? Quote Link to comment Share on other sites More sharing options...
o3d Posted February 13, 2007 Share Posted February 13, 2007 That would work fine for that server but say you migrate your code to another server with a different date-time format? The NOW() function is not dependant on your computer's datetime settings. UPDATE table SET col=NOW() WHERE conditions Quote Link to comment Share on other sites More sharing options...
Lodar Posted February 13, 2007 Share Posted February 13, 2007 In your query you could use CURRENT_TIMESTAMP for the field in place of $date and it will input in the correct format, depending on what column type you have lastLoginDate set to (I.E DATE, TIME or TIMESTAMP) Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 13, 2007 Share Posted February 13, 2007 SELECT DATE_FORMAT(NOW(), '%m-%d-%y') AS DateDisp FROM table WHERE condition Quote Link to comment 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.