Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i want to compare datetime with
GETUTCDATE()


i have a date field and i have a datetime field

i want to take the date field and the time from the datetime field to compare them but i'm getting the error described in the question

What I have tried:

<pre>declare @date date = '2021-08-07' select @date  select case when (cast (@date as nvarchar) + ' ' +  (select cast(convert(time(7),'2021-08-07 09:00:00.000') as nvarchar))) <GETUTCDATE() then 1 else 0 end
Posted
Updated 8-Aug-21 18:08pm

1 solution

select case when CAST((cast (@date as nvarchar) + ' ' +  (select cast(convert(time(7),'2021-08-07 09:00:00.000') as nvarchar))) AS DATE) <GETUTCDATE() then 1 else 0 end


Try the above Code. It Works. You have to convert varchar to date field again to compare with another date field.
 
Share this answer
 
Comments
Member 14800672 10-Aug-21 4:24am    
Hi Anand,
i want to compare dateTime to dateTime and not date to DateTime
so i need the value before get< getutcdate() to be a dateTime and not a date

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900