+ Reply to Thread
Results 1 to 14 of 14

Unable to get the proper time and date output with dd hh:mm:ss

  1. #1
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Smile Unable to get the proper time and date output with dd hh:mm:ss

    Hi Guys,

    Need the experts help on this. Been cracking my head for awhile now with no results

    I have an excel file where I need to minus two dates and time as below:

    A B C D E
    1 Dec 01, 2014 15:51:40 Dec 16, 2014 16:53:32 15 1:1:52 8 20:46:43

    The formula im using is =INT(B1-A1)&" "&HOUR(MOD(B1-A1,1))&":"&MINUTE(MOD(B1-A1,1))&":"&SECOND(MOD(B1-A1,1))
    and the output i'm getting is in C1. How do I instead get the output of 15 01:01:52 instead of 15 1:1:52? I have tried using =B1-A1 but it does not show the correct value if it is more than 31 days hence the reason why I had to use the long formula.

    The reason I need the output as 15 01:01:52 is because I have another column which I need to calculate the difference between column C1-D1 and for that I am using the formula =LEFT(C1,FIND(" ",C1)-1)+RIGHT(C1,8)-(LEFT(D1,FIND(" ",D1)-1)+RIGHT(D1,8)) and it will only accept the calculation if its 15 01:01:52. I could change the 8 to 6 but then I would need to change for a lot of records.

    Is there anyone out there who can help me please

  2. #2
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Welcome to the forum
    Please attach sample fileAttach A File.jpg
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  3. #3
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,373

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Maybe:
    =INT(B1)-INT(A1)&" "&TEXT(MOD(B1,1)-MOD(A1,1),"hh:mm:ss")

  4. #4
    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,959

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    If those really are dates/times, and not just text looking like dates/times, why would you want to convert them to text? It would seem to me to make more sense if you left dates/times in their numeric format, then you can run your calcs on them relatively easily?
    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

  5. #5
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Hi Azumi...Tried your formula but it only works halfway. It works for the above example but when I tried with another example it showed an error.

    A B
    1 Dec 15, 2014 20:39:13 Dec 17, 2014 17:05:50


    When I tried your formula for above, B1-A1, it shows as error. Is there anything can be done?

  6. #6
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Hi FDibbins,

    Sorry I'm still a bit new to excel. The main reason is I need to minus 3 different cells with different data to get the result. The raw data is pulled from a tool. The reason why I subtract from B1-A1 is so that I can have that value in cell C1 and I need to use the value of C1 to subtract cell D1. Sorry if i'm cofusing anyone but in easier terms I would like to subtract B1-A1 then minus C1 and the result would be in D1.

    the format in C1 cell is dd hh:mm:ss

    A1 - Dec 01, 2014 15:51:40
    B1 - Dec 16, 2014 16:53:32
    C1 - 8 20:46:43

  7. #7
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Quote Originally Posted by FDibbins View Post
    If those really are dates/times, and not just text looking like dates/times, why would you want to convert them to text? It would seem to me to make more sense if you left dates/times in their numeric format, then you can run your calcs on them relatively easily?
    Hi FDibbins,

    Sorry I'm still a bit new to excel. The main reason is I need to minus 3 different cells with different data to get the result. The raw data is pulled from a tool. The reason why I subtract from B1-A1 is so that I can have that value in cell C1 and I need to use the value of C1 to subtract cell D1. Sorry if i'm cofusing anyone but in easier terms I would like to subtract B1-A1 then minus C1 and the result would be in D1.

    the format in C1 cell is dd hh:mm:ss

    A1 - Dec 01, 2014 15:51:40
    B1 - Dec 16, 2014 16:53:32
    C1 - 8 20:46:43

  8. #8
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Quote Originally Posted by azumi View Post
    Maybe:
    =INT(B1)-INT(A1)&" "&TEXT(MOD(B1,1)-MOD(A1,1),"hh:mm:ss")
    Hi Azumi...Tried your formula but it only works halfway. It works for the above example but when I tried with another example it showed an error.

    A B
    1 Dec 15, 2014 20:39:13 Dec 17, 2014 17:05:50


    When I tried your formula for above, B1-A1, it shows as error. Is there anything can be done?

  9. #9
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    =INT((B1-A1)-LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8))&" "&TEXT(MOD((B1-A1)-LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),1),"HH:MM:SS")
    Try this
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Quote Originally Posted by nflsales View Post
    =INT((B1-A1)-LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8))&" "&TEXT(MOD((B1-A1)-LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),1),"HH:MM:SS")
    Try this
    Hi NFLSales,

    That worked perfectly!!!!
    Although if the column C1 is empty, is there anyway for it not to show an error as #VALUE? If possible would like it to accept as a cell value 00 00:00:00 that way formula still will work.

    Is there any way to do this?

  11. #11
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    =INT((B1-A1)-IFERROR(LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),0))&" "&TEXT(MOD((B1-A1)-IFERROR(LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),0),1),"HH:MM:SS")
    Try this

  12. #12
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Quote Originally Posted by nflsales View Post
    =INT((B1-A1)-IFERROR(LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),0))&" "&TEXT(MOD((B1-A1)-IFERROR(LEFT(C1,FIND(" ",C1)-1)+MID(C1,FIND(" ",C1)+1,8),0),1),"HH:MM:SS")
    Try this
    Hi again NFLSales,

    It works wonderfully for that. Although I did try it with another value as below:

    A1 - Nov 08, 2014 07:21:14
    B1 - Dec 16, 2014 22:14:29
    C1 - 7 21:42:25
    D1 - 30 21:16:09

    When I ran the formula it returned the result in column D1 but I did a comparison and calculated it manually and also using an online calculator and the result shown is 30 17:10:50 instead of 30 21:16:09. Might be calculation is wrong somewhere?

  13. #13
    Forum Contributor
    Join Date
    01-02-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2007
    Posts
    272

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    Quote Originally Posted by mark888 View Post
    Hi again NFLSales,

    It works wonderfully for that. Although I did try it with another value as below:

    A1 - Nov 08, 2014 07:21:14
    B1 - Dec 16, 2014 22:14:29
    C1 - 7 21:42:25
    D1 - 30 21:16:09

    When I ran the formula it returned the result in column D1 but I did a comparison and calculated it manually and also using an online calculator and the result shown is 30 17:10:50 instead of 30 21:16:09. Might be calculation is wrong somewhere?
    Hi NFLSales,

    Sorry my bad it's working fine..I made an error in validating. Thank you very very much for your help NFLSales and the rest for helping me out!!!
    Works wonderfully now!!!

  14. #14
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: Unable to get the proper time and date output with dd hh:mm:ss

    See below and pls. recheck your calculation
    B1 =41989 22:14:29
    A1 =41951 7:21:14
    B1-A1= 38 14:53:15
    C1 = 7 21:42:25
    D1 = 30 17:10:50

+ 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] VBA code pull data from SQL db - need output dates in proper date format
    By seatejo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2014, 02:28 AM
  2. Help with graphing (Date, Time and Output)
    By amaynew in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 03-09-2014, 10:37 PM
  3. Unable to combine Date and Time
    By sajeel in forum Excel General
    Replies: 3
    Last Post: 06-15-2010, 03:18 PM
  4. incorrect date output when time and date strikes 12 midnight
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-22-2009, 10:04 AM
  5. Replies: 0
    Last Post: 08-23-2005, 12:24 PM

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