+ Reply to Thread
Results 1 to 14 of 14

Need help with Date/Time Conversion

  1. #1
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Need help with Date/Time Conversion

    Hello,

    I have been struggling with an issue for the past 3 days and after exhaustive research and reading forum threads I've yet to find a solution. So I'm hoping someone here can help me or at least point me in the right direction.

    Here's the situation:

    I have been working on a Macro that will take a bunch of imported data (in a .csv file) and format it, extract certain data, and create a printable report to show just the data that is needed. That is all done and works fine.

    However, there is a problem with the date and time data I am importing. The problem is really with the software I am exporting from I think, but I have no control over that, so I'm trying to manipulate the data I get and put it into a workable format.

    So here's the problem...the external software I'm using is exporting the date information wrong. So for example, if I export the transactions from today (Nov 10, 2013), they come into Excel as 10/11/2013 (October 11, 2013). I have checked all my system settings, etc. and there are no issued there. And applying a typical date transformation (i.e., formatting it as mm/dd/yyyy h:mm AM/PM doesn't work because later when I try to add the day in front, the day is wrong because the date is really wrong).

    I was able to figure out how to create VBA code to take the imported date data (which in my case is Column B), add 3 new columns (C, D, and E) and using the Text to Columns function in Excel, convert the dates to the correct format.

    But what I have now looks something like this:

    Column B (Original Date): 10/11/2013 8:30 AM
    Column C: 11/10/2013
    Column D: 8:30
    Column E: AM

    Now what I want to do (and this is where I am stuck) is:

    1) Combine the contents of Columns C, D, and E (producing, for example: 11/10/2013 8:30 AM) into Column F
    2) Delete Columns C, D, and E

    So that after all this conversion, I"m left just with my original columns but with my date now in the proper format.

    To make things a little more challenging, this is something we have to do every day, and every day there are different numbers of rows of data, so I need to write the VBA to dynamically handle the # of rows I have on a give day.

    Any suggestions?

    Your help is greatly appreciated!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need help with Date/Time Conversion

    Post a sample CSV file, 5-10 rows of raw data should be sufficient.
    Post a sample of the final results desired in an Excel sheet.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question Re: Need help with Date/Time Conversion

    Thanks very much for your reply.

    I have attached three files.

    OriginalData: The original CSV file as imported (with duplicates removed)

    DataAfterTransform: The CSV File after I applied a VBA code to transform text to columns and convert the date and time information to mm/dd/yyyy h:mm AM/PM (from dd/mm/yyyy h:mm AM/PM). I couldn't figure out how to do it but only create one column of output data. So now I am trying to combine the 4 created columns back to just 2 columns (Trip Start Date and Trip End Date)

    Desired Outcome: What I want the final result of the transformation to be

    Here is the portion of VBA code I used to transform the data between the first and second files:

    Please Login or Register  to view this content.
    Any help is appreciated!

    Kim
    Attached Files Attached Files
    Last edited by knilsson; 11-11-2013 at 12:29 PM. Reason: fix tags

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Need help with Date/Time Conversion

    I would think your final result would be an Excel workbook...?

  5. #5
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need help with Date/Time Conversion

    No, not really. We won't be saving the processed workbook. We just import the CSV file, run a macro to format it and extract the information we need and then print the result. But I think I got it to work, though admittedly very clumsily. But I guess it will work for now. Thanks anyways for your help.

  6. #6
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Need help with Date/Time Conversion

    check this attchment, if this is what you looking for then ok.
    if not write what exactly you looking for.
    OriginalData.xlsm
    Give Feedback and Click(*)

  7. #7
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Need help with Date/Time Conversion

    this code will do the same job
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need help with Date/Time Conversion

    Thanks so much for you help before. Your code was working great....until we hit the new year. Now the dates are coming out like this:

    Original Downloaded format:

    Start: 2/1/2014 8:30
    End: 2/1/2014 11:30


    Transformed format:

    Start: 1//2/014 8:30:00 AM
    End: 1//2/014 11:30:00 AM

    The way it should be is:

    Start: 1/2/2014 8:30 AM (or 01/02/2014 8:30 AM)
    End: 1/2/2014 11:30 AM (or 01/02/2014 11:30 AM)

    Any pointers on how to modify your code so that they work in the new year? I think the problem is that the months now are only 1 digit, so that is throwing things off. The time is also throwing in the seconds which we don't need.

    Any suggestions?

  9. #9
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Need help with Date/Time Conversion

    Thanks so much for you help before. Your code was working great
    as per forum rule, you should give feedback when you was used my code, not when you need help again. right?

    I was replied you one november 11, 2013, and today is January 03, 2014

    6a. Feedback Rule: •Be responsive - provide feedback to suggested solutions and take the time to thank those who took their time to help you

  10. #10
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need help with Date/Time Conversion

    I'm sorry. You're right.

  11. #11
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Need help with Date/Time Conversion

    try this below code, if its not working as per your requirements please let me know.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need help with Date/Time Conversion

    Thank you so much! That seems to work perfectly. I tried it for several different dates throughout the year and it seems to be robust. Thank you very much for your help.

  13. #13
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: Need help with Date/Time Conversion

    glad i could help and please add MY ADD REP BY CLICKING STAR BUTTON BELOW MY POST. AND MARK THREAD AS SOLVED.

  14. #14
    Registered User
    Join Date
    11-21-2009
    Location
    California
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Need help with Date/Time Conversion

    Will do. Thanks again.

+ 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] Date time stamp to date conversion
    By N8237 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-16-2012, 11:25 AM
  2. Date and time conversion to another time zone
    By RUBEN PARRAS in forum Excel General
    Replies: 1
    Last Post: 05-21-2012, 09:03 PM
  3. Date and Time conversion to hours?
    By hainsworth in forum Excel General
    Replies: 7
    Last Post: 11-04-2010, 12:51 PM
  4. conversion of text to time and date
    By afgi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2010, 12:08 PM
  5. date/time conversion
    By rfcomm2k in forum Excel General
    Replies: 3
    Last Post: 03-22-2009, 08:31 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