简体   繁体   中英

generate timezone specific date and time

My mysql query is as follows:

select * from orders

where orders has created_at field.

Now what i want is i want to convert created_at to 7 am of next day of created_at date . and the time created should be according to local timezone .

Is there a way to achieve it?

Note:: and orders table also has field timezone which has values like Australia/Sydney, Asia/Kolkata etc.

You need to go through the CONVERT_TZ function

// syntax
CONVERT_TZ(your_timestamp_column_name, 'db_timezone', 'your_desired_timezone_name')

// Example
SELECT CONVERT_TZ(`created_at`, 'UTC', `timezone`) as `my_date` FROM orders

Now when you have a date in your desired timezone, you can add hour and time that comes from a difference of next day 7AM and .my_date

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM