查询数据库当天某时间段数据

1、SQL在查询当天记录时要注意是从当天的0点0分0秒0毫秒开始,到次日0点0分0秒0毫秒截止,但不包含次日的0点0分0秒0毫秒。

2、注意:在不同数据库产品中,获得当天日期的函数不一样。

    MSSQL获得当前日期:convert(varchar(10),Getdate(),120)

    MYSQL获得当前日期:date(now())
    Oracle获得当前日期:to_char(sysdate,'yyyy-mm-dd')

    Access获得当前日期:date()

3、在各个数据库里获得当天的记录写法为(假设表名为:Table_1,日期列名为:date_col):

    MSSQL获得当天记录:

1
select * from table_1 where date_col>=convert(varchar(10),Getdate(),120) and date_col=date(now()) and date_col=to_char(sysdate,'yyyy-mm-dd') and date_col=date() and date_col

如果查询固定时间段的数据:
"select * from biao where (here>=date(now()) and here

你可能感兴趣的:(查询数据库当天某时间段数据)