user665997
user665997

Reputation: 313

Trying to read mm/dd/yyyy format in sql while creating table

So I am very new in SQL and I am trying to create a table where I will later import a .csv file. In this table there is a time stamp column that I want to set it up to read mm/dd/yyyy hh:mi:ss, yet I've tried doing this:

 create table Particle_counter_HiSam ( time_utc  timestamp(m/d/Y hh:mi:ss),...

and i get this error

 ERROR:  syntax error at or near "m"

I just can't seem to figure this out.

Any help will do. Thanks!

Upvotes: 2

Views: 146

Answers (2)

DrkWhz24
DrkWhz24

Reputation: 1

if your creating a table for timestapm, just use this..

CREATE TABLE IF NOT EXIST 'Particle_counter_HiSam' 
{

'date_log' timestamp NOT NULL,

}

hope this help..

Upvotes: 0

Dylan Su
Dylan Su

Reputation: 6065

Create the table as normal timestamp and use SET with STR_TO_DATE in load data infile as below.

-- table definition
create table Particle_counter_HiSam ( time_utc  timestamp, ... );

-- load data
load data infile 'data.csv' 
into table Particle_counter_HiSam
fields terminated BY ',' ESCAPED BY ""
lines terminated by '\r\n'
(@var1, c2, ....)
SET time_utc = STR_TO_DATE(@var1,'%m/%d/%Y %H:%i:%S');

Upvotes: 1

Related Questions