How do i change SQL CURDATE() default_timezone?

hello Coders,

I have this sql query that fetch 30 days of records from Database.

SELECT `col1`,`date` FROM `table` WHERE `date` BETWEEN CURDATE() - INTERVAL 31 DAY AND CURDATE()

works good with one exception, it will not obey [php]date_default_timezone_set(‘US/Eastern’);[/php]

and my server and my local time is way too far in time.

First thing I would want to do is set the time zone for the database, not sure how that will affect your data.

setting global time zone

The other thing to do, instead of using the curdate, pass in a date value.

Thanks astonecipher, I found the answer I was looking for, just in case someone might need it.
[php]$dt = new DateTime();
$offset = $dt->format(“P”);
$PDO_link->exec(“SET time_zone=’$offset’;”);//SET time_zone=’-04.00’[/php]

I found this at http://www.sitepoint.com/synchronize-php-mysql-timezone-configuration/ on the comments.

Sponsor our Newsletter | Privacy Policy | Terms of Service