Board index » delphi » SQL Query for Date/Time

SQL Query for Date/Time

I am trying to create a query to pull records from a table between a user
selected start date/time and end date/time.  I know how to do a date or time
separately but I am having a problem structuring the query to combine them.
Example : list all records from 04/14/2000 17:00 to 04/15/2000 06:59 .  Any
help would be appreciated.

Ray Long
r...@mandatasys.com

 

Re:SQL Query for Date/Time


Ray Long <r...@mandatasys.com>

Quote
>... a problem ... list all records from
> 04/14/2000 17:00 to 04/15/2000 06:59.

Ray, Here is one way:

WHERE
  (XDate > "04/14/2000" OR (XDate = "04/14/2000" AND XTime >= "17:00"))
AND
  (XDate < "04/15/2000" OR (XDate = "04/15/2000" AND XTime <= "06:59"))

If you had used a combined date-time field it would not have been so
ugly but that's another story.

Regards, John H

Re:SQL Query for Date/Time


Quote
>I am trying to create a query to pull records from a table between a user
>selected start date/time and end date/time.  I know how to do a date or time
>separately but I am having a problem structuring the query to combine them.
> list all records from 04/14/2000 17:00 to 04/15/2000 06:59

where yourDateTime Between  "04/14/2000 17:00:00" and  "04/15/2000 06:59:00"

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:SQL Query for Date/Time


Quote
> Ray, Here is one way:

> WHERE
>   (XDate > "04/14/2000" OR (XDate = "04/14/2000" AND XTime >= "17:00"))
> AND
>   (XDate < "04/15/2000" OR (XDate = "04/15/2000" AND XTime <= "06:59"))

> If you had used a combined date-time field it would not have been so
> ugly but that's another story.

> Regards, John H

John,
Thanks for the help.  I tried to use a combined field but I did not know how
to create a calculated field in an SQL.  I have done calc fields in a table.
I am using params from a date time picker to set the start/end date/time.
If you have any suggestions please let me know.

Thanks again

Ray

Other Threads