如何在mysql中检查日期计数 [英] how to check date count in mysql

查看:79
本文介绍了如何在mysql中检查日期计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想检查一个人是否今天申请休假,因为我正在传递DateTime.Now作为参数,但是结果却为空,但是表中已经存在如何检查记录的记录?

Hi
I want to check whether a person has applied for leave today for that i am passing DateTime.Now as parameter but i am getting null as result but there records already exists in the table how to check it?

推荐答案

您好Shashwath,

您需要将参数值作为System.DateTime.Now而不是datetime.now传递,然后在数据库中尝试使用下面的查询,它将起作用,


从Table_Name中选择Count(*),其中Convert(NvarChar(15),LeaveDate,103)= Convert(NvarChar(15),@ Parameter_Value,103)
Hi Shashwath,

You need to pass the Parameter value as System.DateTime.Now instead of datetime.now and then in Database you just try the Below Query it will Work,


select Count(*) from Table_Name where Convert(NvarChar(15),LeaveDate,103)=Convert(NvarChar(15),@Parameter_Value,103)


您没有在表中找到匹配项.
从此,DateTime.Now.ToString()以"dd/MM/yyyy hr:min:sec"的格式给出输出.其中包括时间(小时:分钟:秒).所以要检查请假的日期.您只需要发送今天日期的(dd/MM/yyyy)部分.
使用此代码可以实现的目标
You are getting the null value because you are not getting a match in the table.
Since,DateTime.Now.ToString() gives the output in the format "dd/MM/yyyy hr:min:sec". Which includes the time(hr:min:sec). So to check the date of the leave. You only need to send the (dd/MM/yyyy) part of today''s date.
Which you can achieve by using this code
DateTime dtm = DateTime.Now;
string date = dtm.ToString("dd/MM/yyyy");



将此日期"作为参数传递.
接下来在数据库中,您需要将请假日期检查为



Pass this ''date'' as parameter.
Next in the database, you would need to check the leave date as

select CONVERT(VARCHAR(10),leaveDate, 103) as  RequestedDate from Table_Name



它将以(dd/MM/yyyy)格式提供值.


希望这能解决您的问题.
谢谢!!



It will give you the value in the format(dd/MM/yyyy).


Hope this solves your issue.
Thanks!!


这篇关于如何在mysql中检查日期计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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