arthurh88
asked on
sql select where date is equal to or less than today
this isn't quite working
where t2.actionDate <= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
I want to select where t2.actiondate is less than or equal to today, ignoring hours, minutes and seconds on both sides of the comparison
where t2.actionDate <= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
I want to select where t2.actiondate is less than or equal to today, ignoring hours, minutes and seconds on both sides of the comparison
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
first one:
>>DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)
returns you starting of tomorrow so it checks dates less than or equal to today.
second one: converts dates to yyyymmdd format on both sides and checks.
>>DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)
returns you starting of tomorrow so it checks dates less than or equal to today.
second one: converts dates to yyyymmdd format on both sides and checks.
where t2.actionDate < cast(getdate() as date)
either as a datetime or date, the field t2.actionDate can be directly compared to date
either as a datetime or date, the field t2.actionDate can be directly compared to date
select
'Using convert' as [Function used]
, convert(date, getdate()) as [Today cut to Whole Date No Time]
, convert(datetime,convert(date, getdate())) as [Today cut to Whole Date but With Time Also]
union all
select
'Using cast' as [Function used]
, cast(getdate() as date) as [Today cut to Whole Date No Time]
, cast(cast(getdate() as date) as datetime) as [Today cut to Whole Date but With Time]
Function used Today cut to Whole Date No Time Today cut to Whole Date but With Time Also
---------------- ---------------------------------- ---------------------------------------------
Using convert 2013-02-13 2/13/2013 12:00:00 AM
Using cast 2013-02-13 2/13/2013 12:00:00 AM
ASKER
that was it exactly. thank you!