Calculate seconds from two datetime

2019-09-19 10:48发布

I want to write a excel macro, which should calculate the seconds from the two datetime.

I have the following format of datetime in a single column.

DateColumn
--------------------------
2010-01-10-01.07.24.465000
2010-01-10-01.08.25.575000

How to calculate the how many seconds difference in the above datetime using macro?

3条回答
啃猪蹄的小仙女
2楼-- · 2019-09-19 11:05

You are looking for Datediff() Function.

Here you got some documentation. You can choose seconds in the first parameter

Anyways it is better and easier to do this by formula.

查看更多
太酷不给撩
3楼-- · 2019-09-19 11:09

I already answered this....

Excel 2010 : Find seconds between two date time =DATEVALUE(RIGHT(LEFT(B3,10),2)&"/"&RIGHT(LEFT(B3,7),2)&"/"&LEFT(B3,4))+TIMEVALUE(RIGHT(LEFT(B3,13),2)&":"&RIGHT(LEFT(B3,16),2)&":"&RIGHT(B3,9))

pretty bad form to repost... and not give any rep on the first one.

查看更多
家丑人穷心不美
4楼-- · 2019-09-19 11:30

The DateDiff function will give you exactly what you need:

timestamp1 = "2010-01-10-01.07.24.465000"
timestamp2 = "2010-01-10-01.08.25.575000"

myDiff = DateDiff("s", timestamp1, timestamp2) ' use "s" to get difference in seconds

You can find out about the various interval types (seconds in the example above) by looking here for more information

查看更多
登录 后发表回答