如何获取日期格式为2017年3月从mysql中的条件?

如何获取日期格式为2017年3月从mysql中的条件?

问题描述:

我的日期格式为数据库中的yyyy-MM-dd,

我需要将日期搜索为(月份名称,年份)。

在选择查询中我得到正确价值,

但是怎么写条件在哪里?



我尝试了什么:



Im having date format as yyyy-MM-dd in DB,
I need to search date as (monthname,year).
In select query im getting correct value,
but how to write in where condition?

What I have tried:

SELECT 
    E.EmpID,
    E.FirstName,
    (CONCAT(MONTHNAME(date), ', ', YEAR(date))),
    (COUNT(InTime)) AS Present,
    (DAY(LAST_DAY(InTime)) - COUNT(InTime)) AS Absent
FROM
    employee.tblcheck K
        INNER JOIN
    employee.tblemployeedetails E 
    ON E.EmpID = K.EmpID
    group by E.EmpID desc;

如果日期存储在日期字段中,则使用



WHERE YEAR(dateField)= 2017



如果要将日期存储在varchar或其他文本字段中,则不要。将数据存储在反映其原生类型的字段中,以便您可以执行搜索,订购等操作。如果您需要以设置格式显示日期,请在显示时对其进行格式化。
If the date is stored in a date field then use

WHERE YEAR(dateField) = 2017

If you are storing the date in a varchar or some other text field then don't. Store data in fields that reflect their native type so that you can do things like searching, ordering etc. If you need the date in a set format then format it when you come to display it.