如何计算VBA中的时差? [英] How to calculate time difference in VBA?

查看:184
本文介绍了如何计算VBA中的时差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,

  time1 = 6:45 AM 
time2 = 7:30 AM

然后,我需要将它转换为小时(整数)



所以在基本数学中,这是:

  timediff = time2  -  time1 
timediff = 0:45

timediff(以小时计)= 0 +(45/60)
timediff (以小时计)= 0.75

我需要在VBA中执行此操作。有人能帮我吗?
非常感谢!

解决方案

DateDiff()这个( n 表示分钟):

 ?DateDiff(n ,6:45,7:30)/ 60 
0.75


I need to calculate the difference of two different times.

For example,

time1 = 6:45 AM
time2 = 7:30 AM

Then, i need to convert it to hours (integer)

So in Basic Math, this is:

timediff = time2 - time1
timediff = 0:45

timediff(in hrs) = 0 + (45/60)
timediff(in hrs) = 0.75

I need to do this in VBA. Can someone help me? Thanks a lot!

解决方案

DateDiff() computes this (n indicates minutes):

?DateDiff("n", "6:45", "7:30") / 60
 0.75 

这篇关于如何计算VBA中的时差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆