+ Reply to Thread
Results 1 to 5 of 5

Problem with converting date fields

  1. #1
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    Problem with converting date fields

    Sorry, but we just had an analyst leave and were left holding the bag trying to figure out a few calculations... Long time SysAdm - but I don't do stats..

    The problem is calculating out the time a job takes ... It should be easy enough as is should be stop minus start time ... The problem is the date fields looks like this 2-Jun-15 03.25.15.820000000 PM ... Unfortunately, I can't get the output in another format... I have tried doing a custom time field but no luck..

    Help

    Thanks in Advance
    J
    Attached Files Attached Files

  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,929

    Re: Problem with converting date fields

    Hi, welcome to the forum

    See if this will get you started...
    =DATEVALUE(LEFT(D2,FIND(" ",D2,1)))+TIMEVALUE(SUBSTITUTE(MID(D2,FIND(" ",D2,1)+1,8),".",":"))-DATEVALUE(LEFT(C2,FIND(" ",C2,1)))+TIMEVALUE(SUBSTITUTE(MID(C2,FIND(" ",C2,1)+1,8),".",":"))
    copied down.

    You will need to format it as time
    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 Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem with converting date fields

    Hi,

    The problem you have is that the two cells are text not Date/Time numbers hence you can't perform any arithmetic with them until you use some additional functions to first convert them to date/time numbers.

    With text 2-Jun-15 03.26.07.565000000 PM I can see the date, but what is the time. Is this 26 minutes 7.565 seconds after 3:00 p.m.?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Problem with converting date fields

    If my assumption in #3 is correct then perhaps with helper columns

    F2:
    =DATEVALUE(LEFT(C2,FIND(" ",C2)))+IF(RIGHT(C2,2)="PM",12+MID(C2,FIND(" ",C2)+1,2),MID(C2,FIND(" ",C2)+1,2))/24+MID(C2,FIND(" ",C2)+4,2)/1440+MID(C2,FIND(" ",C2)+7,13)/86400

    G2:
    =DATEVALUE(LEFT(D2,FIND(" ",D2)))+IF(RIGHT(D2,2)="PM",12+MID(D2,FIND(" ",D2)+1,2),MID(D2,FIND(" ",D2)+1,2))/24+MID(D2,FIND(" ",D2)+4,2)/1440+MID(D2,FIND(" ",D2)+7,13)/86400

    H2: formatted as h:m:s.000
    =G2-F2

    I2: formatted as a number
    =H2*86400

  5. #5
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    Re: Problem with converting date fields

    Quote Originally Posted by Richard Buttrey View Post
    If my assumption in #3 is correct then perhaps with helper columns

    F2:
    =DATEVALUE(LEFT(C2,FIND(" ",C2)))+IF(RIGHT(C2,2)="PM",12+MID(C2,FIND(" ",C2)+1,2),MID(C2,FIND(" ",C2)+1,2))/24+MID(C2,FIND(" ",C2)+4,2)/1440+MID(C2,FIND(" ",C2)+7,13)/86400

    G2:
    =DATEVALUE(LEFT(D2,FIND(" ",D2)))+IF(RIGHT(D2,2)="PM",12+MID(D2,FIND(" ",D2)+1,2),MID(D2,FIND(" ",D2)+1,2))/24+MID(D2,FIND(" ",D2)+4,2)/1440+MID(D2,FIND(" ",D2)+7,13)/86400

    H2: formatted as h:m:s.000
    =G2-F2

    I2: formatted as a number
    =H2*86400
    This got me what I needed... I needed the delta - ie the time between the two in seconds - so I didn't need the I2 value... Thanks much..

    One wierd thing to note, when I copied the data for G2 - it came up a "TRUE" in the cell even though it was formatted the same way as F2... The G2/F2 code looks the same to me - so I don't know why... I just used the F2 code and manually changed the cell info from c2 to D2 and it works great...

+ 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. Date Problem Converting PDF to Excel
    By Kellbells in forum Excel General
    Replies: 6
    Last Post: 12-16-2014, 05:25 PM
  2. [SOLVED] Date and time converting and summation problem
    By rsami in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-19-2013, 10:20 AM
  3. [SOLVED] Problem with converting a date setting from csv-file
    By HFSBR5 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2012, 10:53 AM
  4. Converting fields to date in design view
    By GeoGreco in forum Access Tables & Databases
    Replies: 2
    Last Post: 03-25-2009, 12:29 AM
  5. Date converting problem
    By Ivan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2006, 04:00 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