WinCC 日期时间差值

想实现以下功能:
首先定义三个 变量,TAG1--BOLL
                                      TAG2-文本16位字符集
                                      TAG3-文本16位字符集
                                      TAG4-文本16位字符集
TAG1为“1”时,读取当前系统日期时间,送到TAG2里,TAG1为“0”时,再次读取当前系统日期时间,送到TAG3里,同时用TAG3减去TAG2,算出日期时间差值,送到TAG4里。

最佳答案

TAG4为两时间的差值,就不应该是文本变量,应该改成有符号16位变量,使用VB脚本:
dim tag1
set tag1=hmiruntime.tags("TAG1")
       tag1.read
dim tag2
set tag2=hmiruntime.tags("TAG2")
       tag2.read
dim tag3
set tag3=hmiruntime.tags("TAG3")
       tag3.read
dim tag4
set tag4=hmiruntime.tags("TAG4")
       tag4.read
if tag1.value=1 then
       tag2.write now
else 
       tag2.read       
       tag3.write now
       temp =DateDiff("n", now, tag2.value) ''n为求两时间秒差值,分钟,小时差值分别用m ,h,天差值用d
       tag4.write temp
end if
set tag1=nothing
set tag2=nothing
set tag3=nothing
set tag4=nothing

提问者对于答案的评价:
答案很好,缺少了一个语句,DIM TEMP,加上之后,没问题
还有 datediff 的使用,n代表分钟,s代表秒,h代表小时,d代表天,有点出入。
总之很感谢!

原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc265580.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2019年6月11日 上午3:51
下一篇 2019年6月11日 上午3:51

相关推荐