Reputation: 33
I have time zone offset in my database field. and I need to compare (created_date + time zone offset) with (current date + time zone offset).
DATE(created_date + INTERVAL timezone_offset SECOND)
i know how to add time zone in created date field. but i have to add time zone with date("Y-m-d H:i:s)
.
I need the following in mysql query,
DATE("use php date function to get current date and time" + INTERVAL timezone_offset SECOND)
SQL Query Sample:
SELECT * FROM `admin` AS `A`
INNER JOIN `timezones` AS `T` ON `T`.`admin_id`=`A`.`admin_id`
WHERE (DATE(A.current_date + INTERVAL T.timezone_offset SECOND) != DATE('current datetime by php function ' + INTERVAL T.timezone_offset SECOND)))
Please help.
Upvotes: 3
Views: 1552
Reputation: 845
You can use date("Y-m-d H:i:s)
function in you sql Query as following.
"SELECT * FROM `admin` AS `A`
INNER JOIN `timezones` AS `T` ON `T`.`admin_id`=`A`.`admin_id`
WHERE (DATE(A.current_date + INTERVAL T.timezone_offset SECOND) != DATE('".date("Y-m-d H:i:s")."' + INTERVAL T.timezone_offset SECOND)));"
You just have to add date("Y-m-d H:i:s") function in Sql Query.
Upvotes: 2
Reputation: 3809
If your MySQL instance has the timezone tables loaded (see http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html), then you can use the very convenient CONVERT_TZ function.
CONVERT_TZ(created_date, {time zone name that created_date is created in}, {time zone name you want})
I use it all the time and it is very handy.
Upvotes: 2