PHP: Parse Dates in CSV with inconsistent date formats

A friend was having trouble with a CSV file that she needs to process via PHP before saving to database. The CSV files uploaded to the server have inconsistent date formats such as:

So I prepared a PHP script that lists possible date formats in an array $possible_date_formats and then iterates through the dates read from the CSV file, matching each against the date formats in the array.

Assuming you have a .csv file with tab-delimited data such as this:

My PHP file will output this when it’s run:

And below is the PHP file I’m talking about.

Related Posts:

Posts that may be related to "PHP: Parse Dates in CSV with inconsistent date formats":

Catzie

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

One comment on “PHP: Parse Dates in CSV with inconsistent date formats

 

Leave a Reply

Your email address will not be published. Required fields are marked *