Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Converting datetime format with AM/PM

Hi,

I got a CSV file with a column named Time that contains a DateTime format like this one:

4/25/2016 09:30:00 PM

All the cells contains data like this

SQL doesn't recognize this kind of format

I would like:

1. Import the data in the right format

2. Separate Date form Time in two separate cells

3. Replace the old Time column with the the new correct ones

 

0 1 477
1 REPLY 1

Hi @FedericoM,

Welcome to Google Cloud Community!

1. SQL can't directly convert your datetime format: While SQL doesn't handle AM/PM directly, Python's pandas library can.
2. Use Python's pandas to manipulate data: Read your CSV into a pandas DataFrame, parse the datetime with format, and separate date and time into separate columns.
3. Save the modified DataFrame: Save the DataFrame with new columns to a new CSV file.
This approach provides a flexible solution for working with your specific datetime format and preparing data for further processing in SQL or other tools.