比较字符串与日期 [英] compare string to date

查看:127
本文介绍了比较字符串与日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为tbcomp的表:

compid int
cstid int
compdat varchar(10)


我以dd/MM/yyyy格式保存compdat的值.
喜欢23-10-2010

我想获取特定日期之间的记录.
我在sql中写了以下查询

从tbcomp中选择*,其中compdat>''13-10-2010''和compdat<''25-1--2010''

但它给出了错误.
请给我建议.


thanx.

i have a table named tbcomp :

compid int
cstid int
compdat varchar(10)


i save the value for compdat in dd/MM/yyyy format.
like 23-10-2010

i want to fetch the records between particular dates.
i wrote following query in sql

select * from tbcomp where compdat>''13-10-2010'' and compdat<''25-1--2010''

but it is giving error.
please suggest me.


thanx.

推荐答案

从tbcomp中选择*,其中compdat在"01/10/2010"和"15/10/2010"之间

从tbcomp中选择*,其中compdat在``01-10-2010''和``15-10-2010''之间
按照您的格式
在运算符u之间使用会得到结果.
select * from tbcomp where compdat between ''01/10/2010'' and ''15/10/2010''
or
select * from tbcomp where compdat between ''01-10-2010'' and ''15-10-2010''
as per ur format
use between operator u will get the result.


这篇关于比较字符串与日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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