Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Australia

asked on

Split a CSV file into 2 files based on date.

Hi EE,

Can you split a CSV file using PowerShell by specific date range, e.g split csv file into two everything before may 30 2018 on the first file and everything after on the second file?

2019-04-30 08:15:34.607 - This is date time format of the file I have and it's the first column of the CSV file.

Any assistance is welcome.

Thank you.
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

HI,
Use Loop to copy specific line into different Text file, per the date captured, inside the file.
Avatar of Zack

ASKER

Hi HuaMin,

What do you mean?

Thank you.
Hi,
You can write to different text file like
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim Fileout As Object
    Set Fileout = fso.CreateTextFile("C:\your_path\vba.txt", True, True)
    Fileout.Write "your string goes here"
    Fileout.Close

Open in new window


per different date you can see from original csv file.
Avatar of Zack

ASKER

HI Huamin,

But's not a txt file it's CSV, as per my request how do I split a CSV into two files based on specific date value.

Thank you.
CSV file is definitely Text file and you could use VBA code to tackle with it.

4. Add the following code line:

Open myFile For Input As #1
Note: this statement allows the file to be read. We can refer to the file as #1 during the rest of our code.

5. Add the following code lines:

Do Until EOF(1)
    Line Input #1, textline
    text = text & textline
Loop
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zack

ASKER

Hi Guys ,

Cheers, this has given something for me to play around with many thanks.