sql server - Unable know the exception in query -
i'm writing below query in sql server
update time_tracker set logout = getdate(), totaltime = substring(convert(varchar(20), (logout - login),120),12,8) time_tracker userid = 0138039 , convert(date, login) = convert(date, getdate());
basically, when user hits logout button i'm trying achieve below.
- enter logout datetime stamp in logout column
- calculate difference between login , logout time , update total time column, bu checking today's date , current user.
when this, i'm getting exception:
msg 8114, level 16, state 5, line 1
error converting data type varchar float.
please let me know i'm going wrong , how can fix this.
also when run below query
select substring(convert(varchar(20), (logout - login),120),12,8) time_tracker;
it working fine, mean i'm getting correct time output.
thanks
you trying hh:mm:ss
logout - login
based on 12,8
in substring
function. , put them float column.
i think better store differences in integer datatype in milliseconds. or use time datatype column.
try use datediff:
select datediff(ms,login,logout) time_tracker;
that give time between 2 dates in milliseconds.
or alter column time
format.
Comments
Post a Comment