G
G
Gam Kit2017-05-19 10:51:04
PHP
Gam Kit, 2017-05-19 10:51:04

How to correctly add date to database using PHP?

Good afternoon.
I am making a website, now at the stage of user registration. In the database, in addition to the basic data, I add the date and time of registration. It is clear how to add all this, but what is the best way to do it, what PHP functions to use, because I need to take into account time zones, the exact date of a certain city, or just add the local time of the node? Are there any online services for such needs or is it always done by scripts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
melnikov_m, 2017-05-19
@GamYus

1) we store the data in the database in the Timestamp
format 2) We display it taking into account our time zone (system time on the server) 3) You need to make sure that the current intl
module is installed on your version of php

S
Saboteur, 2017-05-19
@saboteur_kiev

The registration date must be stored for one time zone, for the server one. It is important for you that the user logged in then and then, and not the user logged in when it was 3 hours in Magadan, and this one when it was 8 hours in Moscow time - you yourself will get confused.
To add a date, you can use not php, but sql itself - now (). Or in general the type of the column is on update now.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question