在两年之间查询 [英] querying between two years

查看:83
本文介绍了在两年之间查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

我有一个日志表,我在那里存储员工详细信息,无论谁登录或注销,

我在下面复制我的查询,

(btw查询在MYsql中)



Hello All,
I have a log table, where I am storing the employee details whoever log in or log out,
I am copying my query below,
(btw the query is in MYsql)

SELECT  * FROM logdetails WHERE DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') >= '01/01/2013' AND DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') <= 01/03/2013



如果我正在搜索2013年1月1日到2013年1月3日之间的记录,上述查询工作正常。



但我真正的问题是,如果我是使用相同的查询在2012年12月1日到第3 Ja之间搜索记录2013年的这个问题,这个查询无法获得记录,




the above query is working fine if I am searching records which are between 1st January of 2013 to 3rd January of 2013.

But my real problem is if I am using the same query to search records between 1st Dec of 2012 to 3rd January of 2013, this query is failing to get records,

SELECT  * FROM logdetails WHERE DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') >= '12/01/2012' AND DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') <= 01/03/2013



<每个人都可以告诉我为什么会发生这种情况。




can anyone tell me reason why this is happening.

推荐答案

为什么需要格式化日期?它存储的形式是什么?当然它被存储为约会?您应该只使用日期对象,我怀疑您的代码失败,因为它进行字符串比较。如果必须比较字符串,请使用YYYY-MM-DD
Why do you need to format the date ? What form is it stored in ? Surely it''s stored as a date ? You should work with date objects only, I suspect your code fails as it does string comparisons. If you must compare strings, use YYYY-MM-DD


这篇关于在两年之间查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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