How to Select Data Between a Date/Time Range in MySQL?
Selecting Data Between a Date/Time Range in MySQL
In MySQL, using the BETWEEN operator can facilitate selecting data that falls within a specific date or time range. When working with datetime columns, it is crucial to ensure that the values used in your query are formatted correctly.
The example provided in the question attempts to select data between two dates in 24-hour Zulu time format. However, an unexpected result is encountered due to an incorrect date format:
select * from hockey_stats where game_date between '11/3/2012 00:00:00' and '11/5/2012 23:59:00' order by game_date desc;
The dates in the query utilize a non-standard format, which causes the comparison to fail. To resolve this issue, the date values must be reformatted into a form recognizable by MySQL.
Correct Solution:
select * from hockey_stats where game_date between '2012-03-11 00:00:00' and '2012-05-11 23:59:00' order by game_date desc;
Here, the dates are adjusted to conform to the ISO 8601 standard, ensuring compatibility with MySQL's datetime datatype. This modification allows for the accurate selection of data within the specified date range.
The above is the detailed content of How to Select Data Between a Date/Time Range in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Reduce the use of MySQL memory in Docker

How do you alter a table in MySQL using the ALTER TABLE statement?

How to solve the problem of mysql cannot open shared library

Run MySQl in Linux (with/without podman container with phpmyadmin)

What is SQLite? Comprehensive overview

Running multiple MySQL versions on MacOS: A step-by-step guide

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?

How do I configure SSL/TLS encryption for MySQL connections?
