简体   繁体   English

检查mysql持续时间的最佳方法

[英]the best way to check duration in mysql

in my mysql table, there are column startYear,startMonth,endYear,endMonth which are all integer (int). 在我的mysql表中,有列startYear,startMonth,endYear,endMonth,它们都是整数(int)。 there I stored the starting year and month, and ending year and month for something.. for example I want to store the duration of my car instalment, so startYear would have 2012, startMonth would have 8, endYear would have 2019, endMonth would have 7 在那里,我存储了某年的开始年和月,以及结束年和月。.例如,我想存储我的汽车分期的持续时间,因此startYear将具有2012,startMonth将具有8,endYear将具有2019,endMonth将具有7

ok so since now the actual current month is 9 (september) and year 2013, what is the best way/query for me to check whether the current month and year is within the startYear,startMonth and endYear,endMonth? 好的,既然现在实际的当前月份为9(九月)和2013年,那么对我来说,检查当前月份和年份是否在startYear,startMonth和endYear,endMonth之内的最佳方式是什么?

BETWEEN将检查值是否大于或等于第一个数字,并且小于或等于第二个数字。

IF (MONTH(CURDATE()) BETWEEN startMonth and endMonth) AND (YEAR(CURDATE()) BETWEEN startYear and endYear))

Try this: 尝试这个:

CURDATE() BETWEEN CONCAT_WS('-', startYear, startMonth, '01')
                  AND CONCAT_WS('-', endYear, endMonth, '31');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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