Reputation: 195
I have field endTime has DateTime data type and status (int). I want to update my status field from 1 to 0 if hour and minute from endTime is equal to hour and minute of current time. the day is absolutely same. so the day is doesn't matter.
How do I do ?
Upvotes: 1
Views: 7103
Reputation: 1269773
You can use datepart()
:
select (case when datepart(hour, EndTime) = datepart(hour, getdate()) and
datepart(minute, EndTime) = datepart(minute, getdate())
then 1 else 0
end) as status
You can also put this into an update, if that is what you really want.
EDIT: The update would be:
update table
set status = (case when datepart(hour, EndTime) = datepart(hour, getdate()) and
datepart(minute, EndTime) = datepart(minute, getdate())
then 1 else 0
end);
Upvotes: 1
Reputation: 195
UPDATE <table> SET status = 0
WHERE datepart(hour, endTime) = datepart(hour,getdate())
AND datepart(minute, endTime) = datepart(minute,getdate());
This is How I do on my SQL-Server 2008.
Upvotes: 1
Reputation: 1361
Try this:
UPDATE <TABLE>
SET STATUS = 1
WHERE MINUTE(GETDATE()) = MINUTE(ENDTIME)
AND HOUR(GETDATE()) = HOUR(ENDTIME)
Upvotes: 0