Tuesday, March 27, 2012

Determine Late from Time

I have a datetime column named Timesheet.StartTime and a datetime column
also named Employee.StartTime and I want to compare the time portion of each
to see if the Timesheet.StartTime is later than the Employee.StartTime. My
problem is that I only need to compare the time portion as the date on
Employee.StartTime is constant. Can anyone give me a tip or where I can
find a solution? Thanks.
DavidCan you give some example?|||Even if you need only time portions - assuming your date portions are
the same, all you need is the difference between the two dates.
Datediff function can exactly give you the difference in hours, mins or
sec. Hope this helps.
Have a look at the following code
declare @.date1 datetime,
@.date2 datetime
set @.date1 = '2006-02-14 13:40:07.603'
set @.date2 = '2006-02-14 15:40:07.603'
select datediff(hh,@.date1,@.date2)
select datediff(mi,@.date1,@.date2)|||Try using datepart() function. This can give you the exact part of the
datetime variable you are after.|||Use datediff
declare @.d1 datetime,
@.d2 datetime
set @.d1 = '2006-02-13 11:44:07.102'
set @.d2 = '2006-02-13 12:44:07.102'
select datediff(ss,@.d1,@.d2)
result is 3600
select datediff(ss,@.d2,@.d1)
result is -3600
so if first date is less than or equal to second date then result will
be >= 0 else it will be < 0
Regards
Amish Shahsql

No comments:

Post a Comment