How do I write a SQL query for a specific date range and date time using SQL Server 2008?

前端 未结 8 442
刺人心
刺人心 2021-01-04 01:33

I need to write a query that will get all the rows in a specified date range and time range.

For example, I want to query all the rows from 5:00PM on 16-Sep-2010 to

相关标签:
8条回答
  • 2021-01-04 01:47

    use DBName

    select * from TABLE_NAME A

    where A.date >= '2018-06-26 21:24' and A.date <= '2018-06-26 21:28';

    0 讨论(0)
  • 2021-01-04 01:49

    Remember that the US date format is different from the UK. Using the UK format, it needs to be, e.g.

    --                                  dd/mm/ccyy hh:mm:ss     
    dbo.no_time(at.date_stamp) between '22/05/2016 00:00:01' and '22/07/2016 23:59:59' 
    
    0 讨论(0)
  • 2021-01-04 01:51

    How about this?

    SELECT Value, ReadTime, ReadDate
    FROM YOURTABLE
    WHERE CAST(ReadDate AS DATETIME) + ReadTime BETWEEN '2010-09-16 17:00:00' AND '2010-09-21 09:00:00'
    

    EDIT: output according to OP's wishes ;-)

    0 讨论(0)
  • 2021-01-04 01:54
    SELECT * FROM TABLE
    WHERE DATE BETWEEN '09/16/2010 05:00:00' and '09/21/2010 09:00:00'
    
    0 讨论(0)
  • 2021-01-04 01:55

    You can try this:

    SELECT * FROM MYTABLE WHERE DATE BETWEEN '03/10/2014 06:25:00' and '03/12/2010 6:25:00'
    
    0 讨论(0)
  • 2021-01-04 01:55

    DATE(readingstamp) BETWEEN '2016-07-21' AND '2016-07-31' AND TIME(readingstamp) BETWEEN '08:00:00' AND '17:59:59'

    simply separate the casting of date and time

    0 讨论(0)
提交回复
热议问题