Php date_default_timezone_set time () VS mysql now ()

I am developing an online shopping system. Only UK customers can place an order from the website.

I am wondering which one is the best method?

date_default_timezone_set ("Europe / London"); $ time = time ();

or

using mysql now () function?

Sometimes a customer may choose a time for delivery or collection.

Note. In the UK, we change time twice a year!

+5
source share
3 answers

, NOW(); , , , , PHP. , , mysql .

+5

PHP :

date_default_timezone_set('GMT');

, MySQL, :

'SET time_zone = "' . date_default_timezone_get() . '";'

, PHP, MySQL , NOW() date('Y-m-d H:i:s') .

, ( ).

+2

, PHP MySQL?

, , , "", , , .

, MySQL NOW(), 24 , PHP. PHP SQL-, , ( , , ), ..

, (, , ). , PHP MySQL, , .

Of course, this will not always be crucial, and you can be pragmatic in this matter - sometimes it’s just inconvenient to return to the database, just to find out what it is! But when it matters, you have to be careful.

Naturally, if two systems are on the same server, this is not a problem, but you should not assume that this will always be the case.

+1
source

All Articles