sql - Selecting Yesterdays Records using DateTime Field -
i'm trying select table of yesterdays records (not lastly 24 hours worth of records). field in question defined datetime
(in access 2007) , formatted dd/mm/yyyy hh:mm:ss
.
my first thoughts (as per many other q&a's) take approach like:
select * sometable dateadded = dateadd("d", -1, now())
as mentioned though, fields format means no results returned status compares time value well.
my next thought convert datetime
fields dates so:
select * sometable cdate(added) = dateadd("d", -1, cdate(now()))
once again, no records returned though.
if run next queries though, both homecoming 29/10/2014
:
--select yesterdays date select dateadd("d", -1, cdate(now())) --returns 29/10/2014 --select date of lastly record select top 1 cdate(added) sometable order added desc --returns 29/10/2014
so question how select yesterdays records?
your clause needs include date/time values yesterday (i.e. 24-hour period between yesterday @ midnight , today @ midnight), need do
class="lang-sql prettyprint-override">select * sometable dateadded >= dateadd("d", -1, date()) , dateadded < date()
sql datetime ms-access select
No comments:
Post a Comment