I'm trying to create a new table from my query-results with the following code while having two different date formats (formatted as text in the tweet table) in the same column:
Create Table tweets_adj
select
t.fullname as company_name,
t.`user` as twitter_user_name,
t.id as tweet_id,
cast(t.likes as unsigned int) as likes,
cast(t.replies as unsigned int) as replies,
cast(t.retweets as unsigned int) as retweets,
case
when right(t.`text`,1)="'" and left(t.text, 2) = "b'" then left(replace(t.`text`, "b'", ""), length(replace(t.`text`, "b'", ""))-1)
when right(t.`text`,1)='"' and left(t.text, 2) = 'b"' then left(replace(t.`text`, 'b"', ''), length(replace(t.`text`, 'b"', ''))-1)
else t.`text` end as content,
case
when STR_TO_DATE(t.timestamp, '%Y.%m.%d %H:%i:%s') is null
then STR_TO_DATE(t.timestamp, '%d.%m.%Y %H:%i')
else STR_TO_DATE(t.timestamp, '%Y-%m-%d %H:%i:%s')
end as timestamp,
t.url,
t.hashtags
from tweets t
limit 1000;
I have to sorts of timestamps in the column timestamp: 20.08.2014 20:17 2014-03-10 02:19:02
I want to unify them to one date format (none specific format preferred) and save them in the right format as a date and then export the whole select into a new query.
Unfortunately I get an error:
Incorrect datetime value: '20.08.2014 20:17:00'
I also found this question but I'm too much of a beginner to understand that solution.
Any help is so much appreciated - Thanks!!