+ Reply to Thread
Results 1 to 10 of 10

difference between 2 dates

  1. #1
    Forum Contributor
    Join Date
    09-30-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    266

    difference between 2 dates

    Hi
    I have 2 dates in 2 cell A1 and A2 in the following format mm/dd/yyyy, hh:mmpm. can i know how would i be able to calculate the number of days difference bet these 2 dates.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: difference between 2 dates

    Try this...
    =IF(DATEDIF(A1,B1,"y")=0,"",DATEDIF(A1,B1,"y")&" years ")&IF(DATEDIF(A1,B1,"ym")=0,"",DATEDIF(A1,B1,"ym")&" months ")&DATEDIF(A1,B1,"md")&" days"

    If you only want the number of days, then just subtract the later date from the earlier 1, and format as general
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Contributor
    Join Date
    09-30-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    266

    Re: difference between 2 dates

    Hi Ford, This formula showed an error value till I removed the time. the date i have is in the follwing format

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: difference between 2 dates

    Attach a sample workbook (not image).

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate.

    Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    FYI: you are more likely to get a quicker response if you post a file so respondents don't have to "guess" how the data is organised and/or formatted.

  5. #5
    Forum Contributor
    Join Date
    09-30-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    266

    Re: difference between 2 dates

    Hi I have inserted a test file. I would want to count the number of days in the following format
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: difference between 2 dates

    As your "dates" are not in Excel date format ...

    Try

    =DATEVALUE(LEFT(A2,10))-DATEVALUE(LEFT(B2,10))+1
    Last edited by JohnTopley; 07-15-2017 at 11:20 AM.

  7. #7
    Forum Contributor
    Join Date
    02-07-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    290

    Re: difference between 2 dates

    Hi @Shamz41,

    If you always have comma before times in your cell, you can try this too:

    =(REPLACE(A2,FIND(",",A2),99,"")+0)-REPLACE(B2,FIND(",",B2),99,"")+1

    Regards,
    Khalid

  8. #8
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: difference between 2 dates

    Quote Originally Posted by Shamz41 View Post
    Hi Ford, This formula showed an error value till I removed the time. the date i have is in the follwing format

    Please Login or Register  to view this content.
    oops forgot about the time part. put the cell refs inside INT(), or use helper column to remove the time with INT, then base the calc on that

  9. #9
    Forum Contributor
    Join Date
    09-30-2014
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    266

    Re: difference between 2 dates

    Thanks both formulas worked perfectly

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: difference between 2 dates

    Happy to help and thanks for the feedback

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Difference between dates
    By Sekars in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-30-2016, 09:47 AM
  2. [SOLVED] Difference between two dates
    By ckk403 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-24-2013, 06:02 PM
  3. Difference between two dates
    By Karthick.icwa in forum Excel General
    Replies: 7
    Last Post: 06-13-2012, 11:45 PM
  4. The difference between two dates
    By hesham63 in forum Excel General
    Replies: 1
    Last Post: 07-29-2011, 03:48 PM
  5. Difference between dates
    By barkaroo in forum Excel General
    Replies: 19
    Last Post: 02-29-2008, 03:45 PM
  6. difference between dates
    By RGB in forum Excel General
    Replies: 2
    Last Post: 07-21-2006, 07:45 AM
  7. difference between dates
    By Clash in forum Excel General
    Replies: 4
    Last Post: 05-26-2006, 03:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1