5

This is really strange for me.

I tried: <?php echo strtotime(date("Y-m-d H:i:s")); ?>

It returned: 1351498120.

Also, when i ran this query: SELECT UNIX_TIMESTAMP(now()) ,

it returned the same result: 1351498120.

But when i tried: <?php echo strtotime(date("2012-10-29 18:00:00")); ?>

It returns: 1351533600.

Whereas, if i run this query: SELECT UNIX_TIMESTAMP('2012-10-29 18:00:00'),

it returns: 1351513800

Now my question is: why the timestamps of php and mysql are same for current date, but different for future dates? Is there a way to compare them for future dates?

(NOTE: I have UTC as default timezone in php)

1
  • 2
    In case your MySQL server runs on a unix/linux system you might be interested in updating your time zone info (usually part of the "normal" os update system, e.g. timezone.rpm) and then use dev.mysql.com/doc/refman/5.5/en/mysql-tzinfo-to-sql.html to refresh MySQL's time zone table. Commented Oct 29, 2012 at 8:30

2 Answers 2

8

There is a 5.5 hour difference between the 2, which indicates it is a timezone issue, on either end. The MySql Server's Timezone could be configured differently.

SET time_zone = timezonename;

can be used to set timezone for the current session. Check MySQL Date and Time Functions

Sign up to request clarification or add additional context in comments.

2 Comments

@sephoy 1351513800 - 1351533600 = 19800; 19800/3600 = -5.5, which makes sense because India is GMT - 5:30
Ok, I wrote this at the top of my page: mysql_query("SET time_zone = '+00:00'"); Now timestamps for both php and mysql are coming same.
2

Try to set the default time zone

http://php.net/manual/en/function.date-default-timezone-set.php

1 Comment

I tried: date_default_timezone_set("UTC"); but it is still same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.