以下每一句效果都一样:
1、Select * from a where date between to_date('2018-1-1', 'yyyy-mm-dd') and to_date('2018-8-1','yyyy-mm-dd')
2、Select * from a where date between to_date('2018/1/1', 'yyyy/mm/dd') and to_date('2018/8/1','yyyy/mm/dd')
3、Select * from a where date between to_date('2018-1-1', 'yyyy/mm/dd') and to_date('2018/8/1','yyyy-mm-dd')
扩展资料
数据库中Date与DateTime的区别
Date:代表xxxx年xx月xx日 只表示前面的日期,是SQL Server 2008新引进的数据类型。它表示一个日子,不包含时间部分,可以表示的日期范围从公元元年1月1日到9999年12月31日,只需要3个字节的存储空间。
DateTime:代表xxxx年xx月xx日xx时xx分xx秒 精确到时分秒,用于做时间戳,日期和时间部分,可以表示的日期范围从公元1753年1月1日00:00:00.000 到9999年12月31日23:59:59.997 ,精确到3.33毫秒,它需要8个字节的存储空间。
以sqlserver为例,假设日期字段为saledate,则当天sql如下:select * from [LHDDXkms].[dbo].
[ST_ PPTN _ R ] where STCD =60432099
and DateDiff(dd,saledate,getdate())=0
其他日期,变更最后的and后面即可。
昨天:and DateDiff(dd,saledate,getdate())=1
一周:and DateDiff(dd,saledate,getdate())<=7
一月:and DateDiff(mm,saledate,getdate())=0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)