简体   繁体   中英

Members site last login date time stamp

I run a website for a local organisation where members log in using their own logins. I have quite basic knowledge, so this may be a simple fix..

I have the following code as part of the php run when they successfully log in which saves their log in date & time to the MySQL database.

$stmt = $pdo->prepare('UPDATE accounts SET lastlogin = CURRENT_TIMESTAMP WHERE id = ?');

The problem is that the date and time stored is 2 hours behind our local time (New Zealand). I've searched around the net for this answer but get lost in everything that's out there? What am I missing in this code to save the date & time as local?

Thanks!

That's because the database's time zone differs from your local time zone. I had the same issue.

This is how I fixed it.

$current_time = date('Y-m-d H:is');
$stmt = $pdo->prepare("UPDATE accounts SET lastlogin = '{$current_time}' WHERE id = ?");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM