aneilg
asked on
sql dates
i have the following query and i want to get the results between 15th and 30th aug.
do i nee to do anything special with the minutes.
AND hl.HISTORY_DATE BETWEEN 'yyyy-dd-mm 00:00:00.000' AND 'yyyy-dd-mm 00:00:00.000'
do i nee to do anything special with the minutes.
AND hl.HISTORY_DATE BETWEEN 'yyyy-dd-mm 00:00:00.000' AND 'yyyy-dd-mm 00:00:00.000'
ASKER
thanks if i try AND hl.HISTORY_DATE BETWEEN '2011-15-08 00:00:00.000' AND '2011-31-08 00:00:00.000'
i get The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
i get The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried not including the time part?
if history_date is a DATE type you can do the same thing, but the .000 part is irrelevant.
if you wanted, you could just use '2011-15-08' and '2011-31-08' with corresponding yyyy-dd-mm in the conversion mask
if you wanted, you could just use '2011-15-08' and '2011-31-08' with corresponding yyyy-dd-mm in the conversion mask
ASKER
i think i had my dd and mm mixed up.
do note, as mentioned in the first post, you date range is NOT going to include any data from August 31. Unless your history_date values are all truncated to midnight (00:00:00)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>> i think i had my dd and mm mixed up
doesn't matter what order they are in, just make sure you specify the same order in your conversion mask
doesn't matter what order they are in, just make sure you specify the same order in your conversion mask
adilet_nasirdi…
that's not legal syntax
that's not legal syntax
ASKER
the results are not what i expected. how do i do something like.
AND hl.HISTORY_DATE BETWEEN '2011-15-08' 'yyyy-dd-mm'AND '2011-31-08'
basically putting the date format in the query.
AND hl.HISTORY_DATE BETWEEN '2011-15-08' 'yyyy-dd-mm'AND '2011-31-08'
basically putting the date format in the query.
already shown above...
http:#37249330
use to_timestamp('2011-15-08', 'yyyy-dd-mm') or to_date('2011-15-08', 'yyyy-dd-mm')
http:#37249330
use to_timestamp('2011-15-08',
sorry
forgotten to delete "BETWEEN"
AND hl.HISTORY_DATE >= '2011-08-15' AND hl.HISTORY_DATE < '2011-08-31'
to get all from 15 to 30(including)
forgotten to delete "BETWEEN"
AND hl.HISTORY_DATE >= '2011-08-15' AND hl.HISTORY_DATE < '2011-08-31'
to get all from 15 to 30(including)
ASKER
AND hl.HISTORY_DATE BETWEEN ('2011-08-15','yyyy-mm-dd' ) AND ('2011-08-31','yyyy-mm-dd' )
i get an error Incorrect syntax near ','.
i get an error Incorrect syntax near ','.
Hi
1) SELECT *
FROM tablename
WHERE
CONVERT(VARCHAR(max), [DateTime], 111) BETWEEN '2008/08/15' AND '2008/08/30'
2) Select * from tablename WHERE
ModifiedDate
BETWEEN
CONVERT(DateTime, '8/15/2008 12:00:00AM',131) AND CONVERT(DateTime,'8/30/200 8 11:59:59PM', 131)
1) SELECT *
FROM tablename
WHERE
CONVERT(VARCHAR(max), [DateTime], 111) BETWEEN '2008/08/15' AND '2008/08/30'
2) Select * from tablename WHERE
ModifiedDate
BETWEEN
CONVERT(DateTime, '8/15/2008 12:00:00AM',131) AND CONVERT(DateTime,'8/30/200
you haven't included the "TO_DATE" or "TO_TIMESTAMP" functions
handle date/time correctly:
https://www.experts-exchange.com/A_1499.html
https://www.experts-exchange.com/A_1499.html
ASKER
thanks
between is the same thing as >= and <=
So, if history_date = 2011-12-07 07:54:23 it will be EXCLUDED from a range that goes up to 2011-12-07 00:00:00
if you want it to be INCLUDED, then either bump up to the next day (which will include 00:00:00 of that day) or use 23:59:59