Skip to main content
improve formatting and grammar
Source Link
NathanOliver
  • 183.4k
  • 29
  • 323
  • 439

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrieve records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 at 08:00.

I tried

SELECT...
Date BETWEEN '2015-01-01' AND '2015-01-02'
AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetime type).?

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrieve records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 at 08:00.

I tried

SELECT...
Date BETWEEN '2015-01-01' AND '2015-01-02'
AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetime type).

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrieve records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 at 08:00.

I tried

SELECT...
Date BETWEEN '2015-01-01' AND '2015-01-02'
AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected.

Can I do what I want or only if I use a single field for date and time (datetime type)?

I have a SQL Server 2014 database with 2 fields:

  • one of type datedate for the record date
  • one of type timetime for the record time.

I want to retriveretrieve records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 ateat 08:00.

I tried SELECT... Date BETWEEN '2015-01-01' AND '2015-01-02' AND Time BETWEEN '16:00' AND '08:00'

SELECT...
Date BETWEEN '2015-01-01' AND '2015-01-02'
AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetimedatetime type).

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrive records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 ate 08:00.

I tried SELECT... Date BETWEEN '2015-01-01' AND '2015-01-02' AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetime type).

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrieve records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 at 08:00.

I tried

SELECT...
Date BETWEEN '2015-01-01' AND '2015-01-02'
AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetime type).

Source Link
ruig
  • 23
  • 3

SQL query between date/time with different fileds for date and times

I have a SQL Server 2014 database with 2 fields:

  • one of type date for the record date
  • one of type time for the record time.

I want to retrive records from the table between 2 dates/ times. Example: from 2015-01-01 at 16:00 until 2015-01-02 ate 08:00.

I tried SELECT... Date BETWEEN '2015-01-01' AND '2015-01-02' AND Time BETWEEN '16:00' AND '08:00'

This fails, as expected...

Can I do what I want or only if I use a single field for date and time (datetime type).