简体   繁体   中英

Timestamp comparison in MySQL for same months / different years

I'm using SQL to query three tables for data analysis. I need to compare timestamps for three months- Jan, Feb, March but over different years.

My code so far for the WHERE clause is:

a.time_stamp BETWEEN '%y%/10/01 00:00:00' AND '%y%/01/01 00:00:00'

and it is not returning the right result. Any thoughts?

MySQL lets you select the month from a date:

select MONTH(now()); // -> 1 (in January)

so you might try (not tested):

WHERE MONTH(a.time_stamp) >= 1 and MONTH(a.time_stamp) <=3

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