What is the best way to manage dates via PHP, MySQL, etc.?

My server is in Dallas. I'm in New York .. both PHP and MySQL have configuration variables for setting the time zone.

How do I get them to work together? What dates should I store in MySQL? How to get PHP to handle a date change based on user preferences?

Keep in mind: I don’t think I have ever had PHP, explicitly set the date, always using "NOW ()" in the queries. However, I foresee the need to do this. How to do it?

I hope that such an experience will help me here.

+5
source share
4 answers

Unix Time . UTC, . , , .

Unix Time (, PHP JavaScript). . MySQL :

UNIX_TIMESTAMP(date)
FROM_UNIXTIME(unix_timestamp)

, , .

+16

, Unix PHP DATE/TIME/DATETIME/TIMESTAMP MySQL. , FROM_UNIXTIME() UNIX_TIMESTAMP(). Unix, / .

+2

GMT ( ), (, EST +6, 6 GMT).

date_default_timezone_set().

, , . , , .

0

mysql- (UTC).
, .

U mysql * 1:

mysql_query('SET time_zone = "'.$timezone.'"');

script.

date_default_timezone_set($timezone);

"2009-01-10 13:30:00", : mysql php.

, 2 , , , . mysql php.

* 1) MySQL .

0

All Articles