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.

  1. enter logout datetime stamp in logout column
  2. 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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -