vb.net - how to subtract and add time difference -


i'm doing assignment total late of day. there 3 columns late in database, it's lateam, latepm , totallate. in lateam if user attends @ 7:31 late 1 min. in latepm if attends @ 1:05 pm late 5 min. need add lateam , latepm totallate 6 mins.

code lateam

  dim timelate timespan     dim time date = #7:30:00 am#     dim zerotime timespan = timeofday - timeofday     if timeofday > #7:30:00 am#         timelate = timeofday - time     else         timelate = zerotime 'output 0:00:00     end if     try         dim cnn new oledbconnection(constring)         query = "insert tbldtr(empid,empname,timeinam,lateam) values ('" & txtinputid.text & "', '" & txtempname.text & "','" & timeofday & "','" & timelate.tostring & "')"         cmd = new oledbcommand(query, cnn)         cnn.open()         cmd.executenonquery()         messagebox.show("you have time in am")         cnn.close()      catch ex exception         msgbox("error: " & errortostring(), msgboxstyle.critical)     end try 

this code latepm , add lateam , latepm

    dim timelate timespan     dim time date = #1:00:00 pm#     dim zerotime timespan = timeofday - timeofday     if timeofday > #1:00:00 pm#         timelate = timeofday - time     else         timelate = zerotime     end if            try         dim cnn new oledbconnection(constring)         query = "update tbldtr set timeinpm = '" & timeofday & "',latepm = '" & timelate.tostring & "', totallate = lateam + latepm"         cmd = new oledbcommand(query, cnn)         cnn.open()         cmd.executenonquery()         messagebox.show("you have time in pm")         cnn.close()      catch ex exception         msgbox("error: " & errortostring(), msgboxstyle.critical)     end try 

my problem can't add lateam , latepm. i'm using vb , msaccess database. lateam , latepm columns have datatype shorttext.

you should store date/time date change fields' data type.

then:

query = "insert tbldtr(empid,empname,timeinam,lateam) values ('" & txtinputid.text & "', '" & txtempname.text & "',#" & timeofday.tostring("yyyy'/'mm'/'dd") & "#,#" & timelate.tostring("yyyy'/'mm'/'dd") & "#)" 

edit

to store time only, use format:

query = "insert tbldtr(empid,empname,timeinam,lateam) values ('" & txtinputid.text & "', '" & txtempname.text & "',#" & timeofday.tostring("hh':'mm':'ss") & "#,#" & timelate.tostring("hh':'mm':'ss") & "#)" 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -