Get data between two dates in MySQL

How can I get values ​​between two dates.

I want to get values ​​between 2010-01-02 and 2010-01-04.

Example:

Value DateTime A 2010-01-01 14:55:12 B 2010-01-02 14:55:12 C 2010-01-03 14:55:12 D 2010-01-04 14:55:12 E 2010-01-05 14:55:12 

Thanks!

+1
source share
2 answers

Take a look

expr BETWEEN min and max

If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise returns 0.

/

For best results when using BETWEEN with a date or time, you should use CAST () to explicitly convert the values ​​to the desired data type. Examples. If you are comparing DATETIME with two DATE values, convert DATE to DATETIME values. If you use a string constant such as '2001-1-1' compared to DATE, string in DATE.

+2
source

I know the answer is already accepted, but I thought I would add a little more to what @astander said. I recently answered a date post and a useful way to extract more useful information from dates using date dimension.

See the next StackOverflow question and look at my answer ...

Select all months within a given date range, including values ​​with 0 values

+1
source

Source: https://habr.com/ru/post/893507/


All Articles