sql server - SQL - substring query result -


i have table following columns

  log_id      int primary key    emp_name    varchar(7) not null   date_log    varchar(23) not null   in_am       varchar(8) null   out_am      varchar(4) null   total_am    varchar(4) null   in_pm       varchar(4) null   out_pm      varchar(8) null   total_pm    varchar(4) null   grand_total varchar(4) null   id          int  foreign key here 

supposed value of in_am , out_am , want difference between did this.

 select cast(out_am datetime) - cast(in_am datetime) table 

the result this:

1900-01-01 00:00:07.000 

but want result

00:00:07 

i try substring this:

select substring((cast(out_am datetime) - cast(in_am datetime)),15,20) table 

but doesn't work.

simply use datetime format of 108 output hh:mm:ss follows:

select convert(varchar(8), (cast(out_am datetime) - cast(in_am datetime)), 108) table 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -