在我的sql数据库中有一个列dateofbirth,其中包含使用此表单的客户的生日:2016年12月31日列类型为varchar(50)。
我需要选择那些日期'和'月'就像datetime.now 这是我的代码:
select name,mobile from memberform where dateofbirth like '" + DateTime.Now.ToString("d/M") + "%'
代码有效。但今天在1-1-2017我观察到它也选择了生日为1-10-xxxx的顾客。为什么会发生这种情况?
答案 0 :(得分:3)
通配符%
将匹配任何字符偶数,尝试更新您的代码以在其后添加另一个/
:
'" + DateTime.Now.ToString("d/M") + "/%'