Jump to content

Way To Change Timezone Of Now()


Recommended Posts

  • 3 weeks later...

This topic is a little old but I think I might be able to add a little bit more information about changing timezones.

 

PHP

Here's an example on how to get and change timezones. Changing the timezone affects functions related to time and date:

<?php
echo date_default_timezone_get(); // Get default timezone used by date/time functions
echo date('Y-m-d H:i:s'); // Get current time

date_default_timezone_set("UTC"); // Change default timezone to UTC
echo date_default_timezone_get(); // Get default timezone used by date/time functions
echo date('Y-m-d H:i:s'); // Get current time

Will output:

America/Los_Angeles
2015-05-01 06:14:49
UTC
2015-05-01 13:14:49

 

SQL

Now, you were probably referring to the NOW() function in SQL.

 

Get timezone used by server:

SELECT @@system_time_zone;

Will output:

PDT

 

Change timezone used by server (for current session):

SET time_zone = '+00:00'; -- Change timezone to UTC
SELECT NOW();

Will output:

2015-05-01 13:16:28

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...