+ Reply to Thread
Results 1 to 15 of 15

how to convert irregular day/time data into excel datetime.

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    how to convert irregular day/time data into excel datetime.

    I'm running into an issue with data I've imported into Excel. One of the columns of data is date/time. Some rows are readable by Excel, while other rows are unreadable. I've tried the tricks I know including LEN, MID, LEFT, RIGHT etc, but nothing seems to work.

    I've attached a small sample of this data, hoping someone can help me figure out a formula which will display both types of timestamps in the same format.

    (the workbook also shows examples of the datetimes I am hoping to get)

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: how to convert irregular day/time data into excel datetime.

    You have a specification problem.

    Cell B3 contains 12/03/2020 20:40:00, and your 'correct' value should be 12/3/2020 20:40, but that obscures things. The formula =TEXT(C3,"yyyy-mm-dd hh:mm:ss") returns 2020-12-03 20:40:00, which means USING YOUR LOCAL SETTINGS the 12/03/2020 in cell B3 is being treated as 3 Dec 2020. In contrast, cell B5 contains 13/03/2020 03:22. Under your local settings, presumably US standard, the 13 as month is invalid, which is why you can't convert it directly, but you convert it manually as 13 Mar 2020, which is very likely correct.

    The specification problem is whether cell B3 is MM/DD/YYYY or DD/MM/YYYY like cells B5 and B6. If B3:B9 all came from someone else, especially from someone outside the US, then I'd figure ALL the dates were in DD/MM/YYYY format, so B3 should be 12 Mar 2020 rather than 3 Dec 2020. Is your Raw Data actually raw data? Do B3:B9 come from a text file?

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: how to convert irregular day/time data into excel datetime.

    I do not see your problem.

    Your formula in C3 filled down works for both data types. =B3*1
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,435

    Re: how to convert irregular day/time data into excel datetime.

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    Hi, rows 5 and 6 give me a #VALUE error when I *1 them.

  6. #6
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    Hi Trevor, when I try that I also get a #VALUE error.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,435

    Re: how to convert irregular day/time data into excel datetime.

    Not sure how I can help then. That works for me with your data

  8. #8
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    (replying to hrlngrv)



    Hi, yes, unfortunately that is what I was getting when I tried this. The data is all from the same source... about 2,000 rows of it in a .csv format (actually ; seperated values). The datetimes are in sequential order, (which I can tell because there is another column with different dates, and they are in sequential order). This inconsistency is how I discovered the problem, because I noticed that the dates weren't in proper order after I had "converted" them using LEFT, RIGHT, MID functions. Another oddity in this info is that the LEN function gives me inconsistent results. Row 7 gives me 10 while Row 8 give me 16 and Row 9 is 11!
    Last edited by jrtaylor; 11-12-2020 at 07:03 PM.

  9. #9
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    In any case I appreciate everyone's help. I think the data is simply corrupted.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,435

    Re: how to convert irregular day/time data into excel datetime.

    As far as I can see, the entries that work with your "conversion" formula, that is, =B3*1 are already dates/times. I know this because, when I change the format to General, I see a number like 44512.44. The two that don't work are text entries. Hence, two parts to my formula.

    Maybe try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: how to convert irregular day/time data into excel datetime.

    Since the original data is in a CSV, the only effective way to handle this is to change that file's extension to .TXT (either rename it using a .TXT extension, or copy the .CSV file to a .TXT file), then open the .TXT file. That triggers the Text to Columns wizard. Select Delimited and click Next, select comma as the delimiter and press Next, then in the area in the bottom of Step 3 of 3, find and select the date column, and in the upper left section select Date and in the drop-down to the right of Date, select DMY. This will have Excel treat that entire column as dates formatted as day, month, year.

    The alternative involves formulas like

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    ADDED: Excel is quite obtuse when it comes to CSV files. Excel will only open them as-is using your local settings. In your case, receiving CSV files from someone with different date settings, you have a lot of extra work. Opening .TXT file copies of .CSV files reduces that extra work. It would be nice for Excel to have the option of launching Text to Columns for CSV files as well as TXT files, but MSFT is extremely loathe to admit it ever makes mistakes, even tacitly, so don't hold your breath waiting for Excel to work like LibreOffice Calc. MSFT simply doesn't care enough about Excel users to provide such an option.
    Last edited by hrlngrv; 11-12-2020 at 07:34 PM. Reason: addendum

  12. #12
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: how to convert irregular day/time data into excel datetime.

    For US region setting as M/d/yy
    Please try at D3

    =--(MID(TEXT(B3,"mm/dd/"),4,3)&REPLACE(TEXT(B3,"mm/dd/yyyy hh:mm"),3,3,))


    or Use Power Query

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Bo_Ry; 11-13-2020 at 03:29 AM.

  13. #13
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    Thank you Bo Rey, that does work. I appreciate your help!

  14. #14
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: how to convert irregular day/time data into excel datetime.

    Quote Originally Posted by hrlngrv View Post
    Since the original data is in a CSV, the only effective way to handle this is to change that file's extension to .TXT (either rename it using a .TXT extension, or copy the .CSV file to a .TXT file), then open the .TXT file. That triggers the Text to Columns wizard. Select Delimited and click Next, select comma as the delimiter and press Next, then in the area in the bottom of Step 3 of 3, find and select the date column, and in the upper left section select Date and in the drop-down to the right of Date, select DMY. This will have Excel treat that entire column as dates formatted as day, month, year.

    The alternative involves formulas like

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    ADDED: Excel is quite obtuse when it comes to CSV files. Excel will only open them as-is using your local settings. In your case, receiving CSV files from someone with different date settings, you have a lot of extra work. Opening .TXT file copies of .CSV files reduces that extra work. It would be nice for Excel to have the option of launching Text to Columns for CSV files as well as TXT files, but MSFT is extremely loathe to admit it ever makes mistakes, even tacitly, so don't hold your breath waiting for Excel to work like LibreOffice Calc. MSFT simply doesn't care enough about Excel users to provide such an option.
    Thank you hrlngrv!

  15. #15
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: how to convert irregular day/time data into excel datetime.

    If you're local date settings are D/M/Y you won't see any problems. This is much more a configuration problem due to the OP's standard US date settings, namely M/D/Y. IOW, this is a class of problem for a US user which is likely only to be discernable by another US user.

    Ain't computing fun?!

+ 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] How to convert datetime axis to show interval in days
    By purple_rain09 in forum Excel General
    Replies: 6
    Last Post: 08-17-2019, 04:28 PM
  2. convert to datetime
    By uinthas in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-07-2017, 05:42 PM
  3. [SOLVED] Convert irregular text into hours
    By thairicci in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-10-2016, 02:05 AM
  4. Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)
    By thagasa in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-14-2013, 07:40 PM
  5. Replies: 0
    Last Post: 04-23-2012, 10:06 AM
  6. Converting Data in Irregular Time Intervals into Regular Time Intervals
    By AlexJT in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2011, 02:42 AM
  7. Convert irregular data to monthly equivalent?
    By RBW in forum Excel General
    Replies: 3
    Last Post: 04-02-2006, 03:40 PM

Tags for this Thread

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