Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 150
Default Difference between two date/time values

Hi,

Cell A1 has 21-04-10 07:00 PM
Cell A2 has 06-06-10 07:52 AM
(the dates are in the dd-mm-yy format)

Cell A3 has the formula =A2-A1 for showing the differences in days and
time and is formatted with the custom format:
dd h:mm:ss

The display in cell A3 is 14 12:52:00. While the difference in hours
is okay, the difference in days should be more than 14 as there is are
31 days of May between the two dates. Is there another format to show
the correct difference in days or should be done some other way?
Please help.

Thanks in advance.

Regards,
Raj


  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: Difference between two date/time values

Hi Raj,

The reason why the difference in days is showing as 14 instead of 31 is because the formula is calculating the difference in 24-hour periods, not calendar days. To get the correct difference in days, you can use the
Formula:
DATEDIF 
function in Excel.

Here's how you can do it:
  1. In cell A3, delete the current formula (=A2-A1).
  2. Enter the following formula in cell A3:
    Formula:
    =DATEDIF(A1,A2,"d")&" "&TEXT(A2-A1,"h:mm:ss"
  3. Press Enter.

The
Formula:
DATEDIF 
function calculates the difference between two dates in a variety of units, including "d" for days. The
Formula:
TEXT 
function is used to format the time difference as hours, minutes, and seconds.

The result in cell A3 should now show the correct difference in days and time. If you want to change the format of the result, you can modify the custom format in cell A3.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Difference between two date/time values

Do you really need the seconds? Your sample entries only show date h:mm.

If using a custom format of dd h:mm:ss the max *displayed* number of days
will be the number of days in the *current month*.

So, you can't use this format if the number of days are expected to be 31.
You'd have to use a formula.

Assuming the date/time in A2 will *always* be = the date/time in A1.

=MAX(0,INT(A2-A1))&" "&TEXT(MOD(A2-A1,1),"h:mm")

--
Biff
Microsoft Excel MVP


"Raj" wrote in message
...
Hi,

Cell A1 has 21-04-10 07:00 PM
Cell A2 has 06-06-10 07:52 AM
(the dates are in the dd-mm-yy format)

Cell A3 has the formula =A2-A1 for showing the differences in days and
time and is formatted with the custom format:
dd h:mm:ss

The display in cell A3 is 14 12:52:00. While the difference in hours
is okay, the difference in days should be more than 14 as there is are
31 days of May between the two dates. Is there another format to show
the correct difference in days or should be done some other way?
Please help.

Thanks in advance.

Regards,
Raj




  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Difference between two date/time values

Formatted as a number =A2-A1 is 45.54

45.54 is the serial number for Tuesday, February 14, 1900 12:52:00PM

That's why you get 14 12:52:00

Enter this formula in A3

=DATEDIF(A1,A2,"d")-1 & " days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm""
minutes ""ss"" seconds""")

Returns 45 days 12 hours 52 minutes 00 seconds


Gord Dibben MS Excel MVP



On Mon, 31 May 2010 08:30:48 -0700 (PDT), Raj wrote:

Hi,

Cell A1 has 21-04-10 07:00 PM
Cell A2 has 06-06-10 07:52 AM
(the dates are in the dd-mm-yy format)

Cell A3 has the formula =A2-A1 for showing the differences in days and
time and is formatted with the custom format:
dd h:mm:ss

The display in cell A3 is 14 12:52:00. While the difference in hours
is okay, the difference in days should be more than 14 as there is are
31 days of May between the two dates. Is there another format to show
the correct difference in days or should be done some other way?
Please help.

Thanks in advance.

Regards,
Raj


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Difference between two date/time values

Doesn't that formula go wrong if the time in A1 is earlier than the time in
A2, Gord?

Isn't it easier not to use DATEDIF, and just to use
=INT(A2-A1) & " days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm"" ?
--
David Biddulph


"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
Formatted as a number =A2-A1 is 45.54

45.54 is the serial number for Tuesday, February 14, 1900 12:52:00PM

That's why you get 14 12:52:00

Enter this formula in A3

=DATEDIF(A1,A2,"d")-1 & " days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm""
minutes ""ss"" seconds""")

Returns 45 days 12 hours 52 minutes 00 seconds


Gord Dibben MS Excel MVP



On Mon, 31 May 2010 08:30:48 -0700 (PDT), Raj wrote:

Hi,

Cell A1 has 21-04-10 07:00 PM
Cell A2 has 06-06-10 07:52 AM
(the dates are in the dd-mm-yy format)

Cell A3 has the formula =A2-A1 for showing the differences in days and
time and is formatted with the custom format:
dd h:mm:ss

The display in cell A3 is 14 12:52:00. While the difference in hours
is okay, the difference in days should be more than 14 as there is are
31 days of May between the two dates. Is there another format to show
the correct difference in days or should be done some other way?
Please help.

Thanks in advance.

Regards,
Raj





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Difference between two date/time values

Tweak...

Assuming the date/time in A2 will *always* be = the date/time in A1.
=MAX(0,INT(A2-A1))&" "&TEXT(MOD(A2-A1,1),"h:mm")


If the date/time in A2 will *always* be = the date/time in A1 then we don't
need the MAX function:

=INT(A2-A1)&" "&TEXT(MOD(A2-A1,1),"h:mm")


--
Biff
Microsoft Excel MVP


"T. Valko" wrote in message
...
Do you really need the seconds? Your sample entries only show date h:mm.

If using a custom format of dd h:mm:ss the max *displayed* number of days
will be the number of days in the *current month*.

So, you can't use this format if the number of days are expected to be
31. You'd have to use a formula.


Assuming the date/time in A2 will *always* be = the date/time in A1.

=MAX(0,INT(A2-A1))&" "&TEXT(MOD(A2-A1,1),"h:mm")

--
Biff
Microsoft Excel MVP


"Raj" wrote in message
...
Hi,

Cell A1 has 21-04-10 07:00 PM
Cell A2 has 06-06-10 07:52 AM
(the dates are in the dd-mm-yy format)

Cell A3 has the formula =A2-A1 for showing the differences in days and
time and is formatted with the custom format:
dd h:mm:ss

The display in cell A3 is 14 12:52:00. While the difference in hours
is okay, the difference in days should be more than 14 as there is are
31 days of May between the two dates. Is there another format to show
the correct difference in days or should be done some other way?
Please help.

Thanks in advance.

Regards,
Raj






  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Difference between two date/time values

Yes.

After seeing Biff's reply I realized there is an easier and more accurate
method.

Your suggestion is basically same as his. although as written, your formula
return an error due to the extra " after mm

My final try.............

=INT(A2-A1)&" days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm"" minutes""")



Gord


On Mon, 31 May 2010 20:28:20 +0100, "David Biddulph" <groups [at]
biddulph.org.uk wrote:

Doesn't that formula go wrong if the time in A1 is earlier than the time in
A2, Gord?

Isn't it easier not to use DATEDIF, and just to use
=INT(A2-A1) & " days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm"" ?


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 150
Default Difference between two date/time values

Thanks to All; these were the insights I was looking for.

Regards.
Raj


On Jun 1, 3:07*am, Gord Dibben <gorddibbATshawDOTca wrote:
Yes.

After seeing Biff's reply I realized there is an easier and more accurate
method.

Your suggestion is basically same as his. although as written, your formula
return an error due to the extra " *after mm

My final try.............

=INT(A2-A1)&" days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm"" minutes""")

Gord

On Mon, 31 May 2010 20:28:20 +0100, "David Biddulph" <groups [at]

biddulph.org.uk wrote:
Doesn't that formula go wrong if the time in A1 is earlier than the time in
A2, Gord?


Isn't it easier not to use DATEDIF, and just to use
=INT(A2-A1) & " days "&TEXT(MOD(A2-A1,1),"hh "" hours ""mm"" ?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date/time difference Caroline Excel Worksheet Functions 4 September 12th 09 02:17 PM
Difference between date and time Joshua Excel Worksheet Functions 7 June 12th 09 05:22 PM
Difference in date and time Arun2902 Excel Discussion (Misc queries) 0 March 9th 07 03:17 PM
Calculating Difference Between Start Date & Time And End Date & Ti Samwar Excel Discussion (Misc queries) 2 December 19th 05 12:42 PM
How do you find the difference between two time values when one i. tubroh730 Excel Discussion (Misc queries) 1 March 25th 05 04:32 PM


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"