We help IT Professionals succeed at work.

How to get sys date/time in GMT-5 in PHP

mychel_normandeau
on
Medium Priority
801 Views
Last Modified: 2008-01-09
Hello!

I want to return a string in that format:
YYYY-MMM-DD H24:MM:SS
(2007-July-20 10:30:00)

I don't know in which time zone the server is set but I want the result to be in GMT-5 time. How do I do this?
Comment
Watch Question

Commented:
One way is this:

$dt = date('Y-F-d H:i:s', gmdate() - 3600 * 5);
Commented:
<?php
putenv('TZ=Etc/GMT-5');
print date('Y-M-d h:i:s');
?>

If you want a timezone of some specific city then you can use like putenv('TZ=Asia/Calcutta') also.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
If I use
date('Y-M-d h:i:s', time() - 18000)
would it work on any server config?

Doest time() gives the current GMT0 unix timestamp?
Commented:
time() defaults to current local time.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.