如何获取日期格式为2017年3月从mysql中的条件? [英] How to get date format as march, 2017 from where condition in mysql?

查看:97
本文介绍了如何获取日期格式为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.


这篇关于如何获取日期格式为2017年3月从mysql中的条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆