+ Reply to Thread
Results 1 to 19 of 19

How do I split the date & time into two separate columns?

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    How do I split the date & time into two separate columns?

    After I imported this data, the date and time is in the same column in the format of "mm/dd/yyyy hh:mm:ss" military time. How do I write a VBA code to split up the date and time into two separate columns. One column would only have "mm/dd/yyyy" while the other only have "hh:mm:ss" in military time.

    Eventually, I need to extract information from the data by looking for a specific time. I would also plot time vs something.

    I don't know if treating it as a string would work, because it would just become a text rather than a time, right?

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,176

    Re: How do I split the date & time into two separate columns?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Hi Nanner,

    I put a "long" date ("mm/dd/yyyy hh:mm:ss") in "A1" then ran this:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: How do I split the date & time into two separate columns?

    Hi bananajelly,

    This also can be easily done by two short formulas

    For Date

    =INT(A1)

    Format as Date

    For Time

    =MOD(A1,1)

    Format:Custom: [h]:mm

    A
    B
    C
    1
    8/20/2014 16:07
    8/20/2014
    16:07
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    Thanks Ranman. It was like magic! This is also the first time I heard of the While - Wend statement. I usually only use the While - Loop statement. Cool.

  6. #6
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    xladept, who is "Nanner."

    This worked, too! Thanks! However, I am not too familiar with the "Sub SplitLongData(): Dim D" statement.

  7. #7
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    xladept, who is "Nanner?"

    This worked, too! Thanks! However, I am not too familiar with the "Sub SplitLongData(): Dim D" statement.

  8. #8
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    Thanks AlKey. I actually need to write it in VBA. But what you suggested is useful for times when I just want to do it manually. Thanks!

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Nanner is a diminutive for Banana - The
    Please Login or Register  to view this content.
    is the name of the sub and declaration of a variant for the little array And, thanks for the rep!

    BTW - using Colons the whole routine could be written on one line:

    Please Login or Register  to view this content.
    Last edited by xladept; 08-20-2014 at 04:54 PM.

  10. #10
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    I didn't know about the trick with the colon. Thanks!

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Yeah that saves a lot of space - you cant use it with If..Then.

  12. #12
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    Hey xladept, I've been using your code to split up the date and time. However, I just realized that it does not maintain the data in military time when I run it.

    My DateTime data is in the form of "8/22/2014 00:00:10." But when I run your code to split up the date and time, I get "8/22/2014" and "12:00:10" in separate cells instead of "00:00:10." This causes problems for me now, because I want to also convert the hh:mm:ss into decimal format.

    Thanks.

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Hi Nanner,

    It works with general formatting?

  14. #14
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    xladept, I tried general formatting. It doesn't do anything. It's already in the correct format of "hh:mm:ss." Even when I try to format it in military time, it still reads it as 12:00:10 instead of 00:00:10.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Can you post a sample sheet?

  16. #16
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    Okay, I think the file is attached. Thanks for your help!
    Attached Files Attached Files

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Hi Nanner,

    See if this works for you:

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    07-29-2013
    Location
    California, United States
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: How do I split the date & time into two separate columns?

    Thanks xladept. It works.

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: How do I split the date & time into two separate columns?

    Excellent!

    BTW - You should mark this thread as solved. (Go to Thread Tools up top)

+ 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. Replies: 1
    Last Post: 07-03-2012, 05:49 PM
  2. Split date into 3 separate columns
    By paulr24 in forum Excel General
    Replies: 4
    Last Post: 01-25-2012, 01:51 PM
  3. Merging separate date and time columns into one
    By Gadgets in forum Excel General
    Replies: 5
    Last Post: 07-26-2006, 04:24 PM
  4. [SOLVED] Split a date/time column into 2 columns
    By RKMiller in forum Excel General
    Replies: 1
    Last Post: 12-19-2005, 12:10 PM
  5. Replies: 0
    Last Post: 08-23-2005, 12:23 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