[英]MySql: Create datetime from year and month
I have the following query: 我有以下查询:
SELECT count(*) as 'count'
FROM myTable
WHERE myDateTime >= DATE1 AND myDateTime < DATE2
- myDateTime
is of type datetime ( 2013-01-30 08:48:13
) in myTable
. - myDateTime
是datetime类型(的2013-01-30 08:48:13
中) myTable
。
- DATE1
and DATE2
should be created as datetime also so I could compare them, like this: -还应将DATE1
和DATE2
创建为日期时间,以便我可以将它们进行比较,如下所示:
- DATE1
should to be created from year (eg 2013) and month (eg 01) parameters, and the day should always be 01 (the first day of the month) -应该从年份(例如2013)和月份(例如01)参数创建DATE1
,并且日期应始终为01(每月的第一天)
- DATE2
should be same as DATE1
with an added month. DATE2
应该与DATE1
相同,但要加上一个月。 (if DATE1
is 2013-01-01 00:00:00
then DATE2
should be 2013-02-01 00:00:00
) (如果DATE1
是2013-01-01 00:00:00
则DATE2
应该是2013-02-01 00:00:00
)
You can create the date as a number and then convert it to a date: 您可以将日期创建为数字,然后将其转换为日期:
where myDateTime >= date(@year * 10000 + @month * 100 + 1) and
myDateTime < date_add(date(@year * 10000 + @month * 100 + 1), interval 1 month)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.