Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:21:27+00:00 2026-06-08T20:21:27+00:00

I use MySQL DATETIME column to store date & time. Dates are in UTC.

  • 0

I use MySQL DATETIME column to store date & time. Dates are in UTC. I want to select item from one day. What i’m doing now:

SELECT * FROM data WHERE DATE(CONVERT_TZ(datetime, 'UTC', 'Australia/Sydney')) = '2012-06-01'

note that the timezone depends on user

Problem is that it is quite slow with table growing.
Is there any solution how to make it faster?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:21:28+00:00Added an answer on June 8, 2026 at 8:21 pm

    Currently your query has to compute the conversion for every row of the database. You probably could make things better by converting the other way round, so that the conversion only occurs once (or actually twice, as you’ll have to form a range). Then a proper index on datetime should make things pretty fast.

    SELECT * FROM data
    WHERE datetime BETWEEN CONVERT_TZ('2012-06-01 00:00:00', 'Australia/Sydney', 'UTC')
                       AND CONVERT_TZ('2012-06-01 23:59:59', 'Australia/Sydney', 'UTC')
    

    Or if you worry about a 23:60:00 leap second not getting matched by any query, you can do

    SELECT * FROM data
    WHERE datetime >= CONVERT_TZ('2012-06-01', 'Australia/Sydney', 'UTC')
      AND datetime < CONVERT_TZ('2012-06-01' + INTERVAL 1 DAY, 'Australia/Sydney', 'UTC')
    

    In the latter form, you wouldn’t have to add the hours PHP-side but instead could simply pass the date as a string parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use PHP to insert date into mysql datetime field. $time =
I'd like to use MySQL in this form: SELECT 1 AS one, one*2 AS
How to select data from mysql table past date to current date? For example,
I have a MySQL database , with a column that is date type DATETIME
Ok, I am storing a Date/Time in a MySQL TEXT field. I want to
I have a datetime column in MySQL let's call it $time . It's coming
I use MySQL 5.5.16. I'm trying to check if a certain column exists in
I'd like to use MySQL from SilkJS under OSX Lion, but can't find the
I have my records in mysql stored with a datetime column. I would like
i have use the DateTime control that show only time in my design view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.