且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel日期/时间计算

更新时间:2022-10-15 12:25:13

请尝试:

  = DATE(MID(B1,11,4),MID(B1,8,2),MID (B1,5,2))+(MID(B1,16,2)+ RIGHT(B1,2)/ 60)/ 24-A1 

并将单元格格式化为[hh]:mm。


I'm trying to calculate the difference between two times that are given in this format:

Fri 07/02/2014 10:16 with the cell using a custom format ddd dd/mm/yyyy hh:mm

and display the result in hours.

I have two dates/times:

A1                    B1
Fri 07/02/2014 10:00  Fri 07/02/2014 10:42

The formula I have in C1 is

=TEXT(TIME(LEFT(RIGHT(B1,5),2),RIGHT(RIGHT(B1,5),2),0)-TIME(LEFT(RIGHT(A1,5),2),RIGHT(RIGHT(A1,5),2),0),"h")

Which gives me the answer 4, which I thought should be something like 0.68

Can anyone help?

Thanks

UPDATE:

A1 is actually in this format 07/02/2014 10:00:00, which is then displayed as Fri 07/02/2014 10:00

B1 is entered as 'Fri 07/02/2014 10:42' and displayed as 'Fri 07/02/2014 10:42'

Please try:

=DATE(MID(B1,11,4),MID(B1,8,2),MID(B1,5,2))+(MID(B1,16,2)+RIGHT(B1,2)/60)/24-A1

and format the cell as [hh]:mm.