以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]时间计算(已解决)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=76383)

--  作者:yyzlxc
--  发布时间:2015/10/28 8:47:00
--  [求助]时间计算(已解决)

如何修改代码,当第五列为空时,第六列等于第四列至当前系统时间的时间差,请各位老师指教,谢谢!!

按钮代码如下:
For Each dr As DataRow In DataTables("表C").DataRows
    If dr.IsNull("第四列") Or dr.IsNull("第五列") Then
        dr("第六列") = Nothing
    Else
        Dim tp As TimeSpan
        tp = dr("第五列") - dr("第四列")
        dr("第六列") = tp.TotalSeconds()
    End If
Next
 
 
 下载信息  [文件大小:   下载次数: ]
点击浏览该文件:管理项目14.foxdb

[此贴子已经被作者于2015/10/28 9:23:13编辑过]

--  作者:大红袍
--  发布时间:2015/10/28 9:09:00
--  
For Each dr As DataRow In DataTables("表C").DataRows
    If dr.IsNull("第四列") Then
        dr("第六列") = Nothing
    Else If dr.IsNull("第五列") Then
        Dim tp As TimeSpan
        tp = Date.now - cdate(dr("第四列"))
        dr("第六列") = tp.TotalSeconds()
       
    Else
        Dim tp As TimeSpan
        tp = dr("第五列") - dr("第四列")
        dr("第六列") = tp.TotalSeconds()
    End If
Next

--  作者:yyzlxc
--  发布时间:2015/10/28 9:17:00
--  
谢谢大红袍老师的回复,如何去掉毫秒的数值,还请老师指教,谢谢!!
--  作者:大红袍
--  发布时间:2015/10/28 9:19:00
--  
For Each dr As DataRow In DataTables("表C").DataRows
    If dr.IsNull("第四列") Then
        dr("第六列") = Nothing
    Else If dr.IsNull("第五列") Then
        Dim tp As TimeSpan
        tp = cdate(format(Date.now,"yyyy-MM-dd HH:mm:ss")) - cdate(dr("第四列"))
        dr("第六列") = tp.TotalSeconds()
       
    Else
        Dim tp As TimeSpan
        tp = dr("第五列") - dr("第四列")
        dr("第六列") = tp.TotalSeconds()
    End If
Next

--  作者:yyzlxc
--  发布时间:2015/10/28 9:23:00
--  
谢谢大红袍老师,问题解决!