数据库查询日期在
⑴ 数据库的日期区间查询方法。
access中有个mid函数,可以用来截取字符串或者日期。
select * from 表名 where mid([TestTime],5,10) ='04/19/2013'其中,5代表截取的开始位置,从左数,10代表截取的长度。
数据库的日期区间查询有两种情况:
1:查询给定时间在开始时间列与结束时间列范围中数据;
2:查询日期列在开始时间列与结束时间列范围中数据。
第一种:<,>, <= , >=
select * from 表名 where 日期列 >= to_date('2015-10-20 00:00:00','yyyy-mm-dd hh24:mi:ss')
and t.日期列 <= to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
第二种 between and
select * from 表名 where 日期列 between to_date('2015-10-20 00:00:00','yyyy-mm-dd
hh24:mi:ss')and to_date('2015-10-20 23:59:59','yyyy-mm-dd hh24:mi:ss')。
(1)数据库查询日期在扩展阅读:
sql数据库语句:
创建数据库:
CREATE DATABASE database-name。
删除数据库:
drop database dbname。
创建新表:
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)。
删除新表:
drop table tabname。
增加一个列:
Alter table tabname add column col type。
添加主键:
Alter table tabname add primary key(col)。
删除主键:
Alter table tabname drop primary key(col)。
创建索引:
create [unique] index idxname on tabname(col….)。
删除索引:
drop index idxname。
创建视图:
create view viewname as select statement。
删除视图:
drop view viewname。
参考资料来源:网络-sql语句大全
⑵ SQL 如何查询日期在一定范围内的数据
select * from 表 where 日期字段>='开始日期' and 日期字段<='截止日期' and convert(char(8),日期字段,108)>='开始时间' and convert(char(8),日期字段,108)<='截止时间'。
SELECT * FROM 表明 WHERE 日期字段名 BETWEEN '20130101' AND '20130130'。
例如:
select * from tb1 where dDate>='2010-11-05' and dDate<='2010-11-15'
and convert(char(8),dDate,108)>='8:00:00' and convert(char(8),dDate,108)<='9:00:00'.
select * from table1where year(d)=2010 and month(d)=7 and day(d) between 1 and 31
and (Datepart(hour,d)>=22 or Datepart(hour,d)<6)
(2)数据库查询日期在扩展阅读:
SQL查询日期:
今天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=0
昨天的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())=1
7天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=7
30天内的所有数据:select * from 表名 where DateDiff(dd,datetime类型字段,getdate())<=30
本月的所有数据:select * from 表名 where DateDiff(mm,datetime类型字段,getdate())=0
本年的所有数据:select * from 表名 where DateDiff(yy,datetime类型字段,getdate())=0
参考资料:SQL_网络
⑶ SQL查询access数据库日期
SQL查询access数据库日期的方法如下:
1,打开access,点击创建,点击查询设计,打开后切换成SQL语句。
2,在框框中输入以下语句:SELECT * from 学生 where 出生日期=#日期#;
以下以查询1992/7/11日的学生为例: