+ Reply to Thread
Results 1 to 13 of 13

UK Date (TEXT) to US Data

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2013
    Posts
    35

    UK Date (TEXT) to US Data

    Hi, I have a CSV file where the 1st Column has the Date/Time as a Text String in format "DD/MM/YYYY hh:mm"

    e.g. 21/11/2020 00:15

    I need to change this to a US Date only format "MM/DD/YYYY"

    e.g. 11/21/2020

    Anyone help with the code to do this?

    Sample file attached.

    Thanks,
    Mark
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,927

    Re: UK Date (TEXT) to US Data

    I see that your profile indicates you are using 2007. If you have upgraded, please adjust your profile to reflect a newer version. If you are using a newer version then Power Query is an option for you.

    Here is the Mcode for PQ
    Please Login or Register  to view this content.
    Excel 2016 (Windows) 32 bit
    A
    B
    C
    D
    E
    1
    Date SFN BW Metric Name Value
    2
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    1.387
    3
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    1.437
    4
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    1.337
    5
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    1.441
    6
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    2.276
    7
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    2
    8
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    2.54
    9
    11/21/2020 Atlanta_GigabitEthernet0/3/2 500M To Site Port Utilisation
    2.479
    Sheet: Sheet1
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    09-18-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2013
    Posts
    35

    Re: UK Date (TEXT) to US Data

    Thanks alansidman, I'm using 2013 now so have updated and will try suggestion.

    Never used PQ so may need to look that up

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

    Re: UK Date (TEXT) to US Data

    You could fix such files using batch files at a command line.

    CORRECTION: I misread the part about reducing date+time to date only.

    fix-csv.cmd
    Please Login or Register  to view this content.
    Save this in a directory in your PATH, then open a console window, change to the directory containing sample.csv, and run fix-csv sample.csv . That would create a new sample.csv file with dates in ISO format, yyyy-mm-dd, which Excel would interpret correctly under ALL Windows regional settings, not just UK and US. The original file would be renamed sample.csv.save just in case.

    Better still would be to change the date format in the upstream system which generates these CSV files to use ISO date format.
    Last edited by hrlngrv; 12-05-2020 at 01:05 AM. Reason: correction

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,560

    Re: UK Date (TEXT) to US Data

    This swops the position of Date/Month and create a new csv file named _New in the same folder of original csv file.
    Please Login or Register  to view this content.
    Last edited by jindon; 12-05-2020 at 12:28 AM. Reason: Missed a question mark in Patter.

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

    Re: UK Date (TEXT) to US Data

    OP's sample file may only be an abbreviated sample. A TextStream .ReadAll call and the RegExp replace on the entire file in one go may be suboptimal if the OP's actual CSV files are large.

  7. #7
    Registered User
    Join Date
    09-18-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2013
    Posts
    35

    Re: UK Date (TEXT) to US Data

    Thanks everyone - a few things to try the CSV will typically have circa 20,000 rows.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,560

    Re: UK Date (TEXT) to US Data

    Quote Originally Posted by britinva View Post
    the CSV will typically have circa 20,000 rows.
    Not huge...

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,927

    Re: UK Date (TEXT) to US Data

    Not large for PQ either.

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

    Re: UK Date (TEXT) to US Data

    The question is best tool for the task. In part, that'd mean least code needed. FWIW, this would be simpler using command line tools.

    gawk "{ print gensub("^([0-9]+)/([0-9]+)/([0-9]+) [0-9:]+", "\\3-\\2-\\1", 1) }" sample.csv > new.csv

    There may be a clever Powershell 1-liner, but I just can't force myself to use Powershell.

    Actually, if one had Vim, so ex for the command line, one could edit sample.csv in place.

    ex -c "g;^\([0-9]*\)/\([0-9]*\)/\([0-9]*\)[ :0-9]*;s;;\3-\2-\1;" -c 'wq' sample.csv

    My point here is that while PQ and VBA with or without Windows Script Host embellishment can handle this, they're considerably wordier than command line tools. Also, command line tools could run asynchronously in the background.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,560

    Re: UK Date (TEXT) to US Data

    Quote Originally Posted by hrlngrv View Post
    The question is best tool for the task. In part, that'd mean least code needed.
    That's only your opinion.
    This is a VBA forum, so choice is up to OP.

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

    Re: UK Date (TEXT) to US Data

    Quote Originally Posted by jindon View Post
    . . . That's only your opinion. . . .
    Did I ever state or imply otherwise?

    However, I'd note that for others with similar problems but using Macs, Windows Script Host and full Power Query aren't available. Neither would be Windows batch files, but command line tools like ex would be.

  13. #13
    Registered User
    Join Date
    09-18-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2013
    Posts
    35

    Re: UK Date (TEXT) to US Data

    Thanks again everyone, for me the VBA sub was what was looking for as will be part of a larger VBA script to manipulate the data

+ 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: 3
    Last Post: 02-05-2020, 09:26 AM
  2. Replies: 10
    Last Post: 08-09-2017, 02:17 AM
  3. [SOLVED] Text to Date/Minute data
    By chipps24 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-06-2017, 06:29 AM
  4. [SOLVED] Converting Date Text to Number format to use in a VLOOKUP to polpulate data based by date
    By Rossovich in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 04-08-2015, 10:43 AM
  5. How to update Text Box2 with date 14 days after selected date in Text box1...
    By mjc61 in forum Access Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2014, 09:17 PM
  6. Replies: 1
    Last Post: 02-14-2013, 10:40 PM
  7. Need to capture date data in a text string containing a date and time stamp
    By Grilleman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-07-2013, 01:14 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