且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在mysql中检查日期计数

更新时间:2023-11-26 11:24:40

您好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!!