Jump to content

Setting the current date in mySQL


CincoPistolero

Recommended Posts

<?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);

?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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