Jump to content

Recommended Posts

In my PHP app, whenever a person logs in, I store the current date and time in the 'user' table in the 'lastlogin' column, which is a DATE type. Here is my SQL statement:

    $query = "UPDATE user SET numlogin=".$n.", ".
    "lastlogin=NOW() ".
    "WHERE userid=".$_SESSION['myuserid'].";";

 

I also increment the number of logins, just for fun.

 

However the NOW() SQL function is storing the server time (I believe). How can I get it to store my local time? I want to add 3 hours to the time I'm getting from NOW().

 

Also, my American city does Daylight savings time, so the difference will sometimes be 3 hours, sometimes 4 hours. How can I account for that?

 

Thanks.

 

Perhaps I can do this another way. I have my 'lastlogin' as an SQL 'datetime' type field. Is there a PHP function which returns the local time which can be stored in this field type? Or is there a way I can get the server time and just add 3 hours using PHP?

 

It is best to store a GMT time in database, and convert it to user timezone when displaying.

 

See some useful functions here:

http://www.php.net/manual/en/ref.datetime.php

 

I agree. I've stored using the local time of the server and converted before. It's not fun when you forget to change server time zones later.

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.