MySQL CSV Imported Year Dates as 0018 Invalid Date - mysql

Getting an error when trying to correct the year portion of imported dates.
CSV Date Column Values were formatted
07/21/18 instead of
07/21/2018
This caused MySql to Insert Date as 07/21/0018
I was under the impression that year values in the range 00-69 were converted to 2000-2069 as stated in the documentation.
Any way to fix this? I've tried quite a few statements with no luck...
Any help appreciated

Assuming you want to just update the data in place, and it is a column of Date, DateTime or Timestamp types, you could do this:
UPDATE table SET date = date + INTERVAL 2000 YEAR WHERE YEAR(date) < 70

Related

STR_TO_DATE returns null

I'm trying to convert a string to date with a format of yyyy/mm to yyyy
STR_TO_DATE(SUBSTRING(time,1,4), '%Y')
This returns null for every value as well as when I try to convert without getting rid of the mm:
STR_TO_DATE(REPLACE(time,'/',''), '%Y%m')
This method has worked for me before, I'm at a loss for what I'm missing.
Thanks in advance!
Edit for clarification:
Eventually I am going to insert the year into a column with data type year, so I need to convert a varchar to a date type so I can extract the year in order to insert the data into a new table
I am in the process of making sure it will work before populating the new column with a command like this:
INSERT INTO table (year)
SELECT STR_TO_DATE(SUBSTRING(time,1,4), '%Y')
FROM `origtable`
I'm trying to convert a string to date with a format of yyyy/mm to yyyy
Just use left():
select left(time, 4) as yyyy
There is no need to convert to a date or datetime. You want a simple string operation.
EDIT:
year is a really weird type. I would just use an integer. But if you are using it, you can insert a full date into the field:
select date(concat(time, '/01'))
The resulting date can be inserting to a year column.

Mysql converting double or int into a date or month

This might be a re-post, but I haven't been able to find anything that answers the question for me. I have a table with days listed as doubles like 435.6 or 5.2 and I need to convert this into a month. I've tried:
SELECT day FROM table WHERE DATE_ADD('2014-01-01', INTERVAL 31 DAY);
But that query just spits out the same. Any help please.
edited version:
Assuming your table is named t and your decimal column is named d
select date_format(date_add('2014-01-01', interval d day),"%m") from t;
This should add your epoch date ('2014-01-01') and format the result as a number (00-12), after adding d days to the epoch. For the month represented as a word (January-December), use "%M". here's documentation for DATE_FORMAT.
here is a fiddle of the above code working for sample values

MYSQL Insert date today with specific format query

Hi I want to insert a data into table with the date today with a specific date format. My date in column is set to like dd-mm-yyyy but i want to insert a date in literal form like 28 October 2016
I know how to insert the current date today and also know how to select date with specific format but I'm having a little confusion with combining this two queries
For inserting current date:
INSERT INTO product_table(product_names, product_type,product_brand,product_price,product_count,product_note, product_date) VALUES ('Logitech','Mouse','Sample',100,5,'1 year warranty',CURRENT_DATE)
For selecting with specific date format
Select DATE_FORMAT(product_date, %d %M %Y) from product_table;
Thank you
If you want to store a date in a column as 28 October 2016, you'll need to make it a VARCHAR field or something.
If that's the case, I don't why you'd want to insert it like that, rather than just format it on the way out of the database?

What date time datatype i should use to insert date like March2016 in mysql?

As i am trying to insert the date 'March16' which is March 2016 in mysql table x with datatype DateTime. But this gives me error incorrect date value.
Please help me . Thank you very much
'March16' is not a correct date format. You need to do STR_TO_DATE() or DATE_FORMAT().
Read more about above two.
If you want to insert only month and date
Mysql doc
Ranges for the month and day specifiers begin with zero due to the
fact that MySQL permits the storing of incomplete dates such as
'2014-00-00'.
This means that to store the year and month only, you
can use a DATE column and put 00 instead of the day. e.g 2013-12-00.

MYSQL Date - str_to_date() function messed with year in my dates

Just changed the date from the format dd-mm-yy using str_to_date() function in MYSQL.
The column date had the date in dd-mm-yyyy format. I used following query :
UPDATE invoice SET date=str_to_date(date, '%d-%m-%Y');
and dates got converted to correct format yyyy-mm-dd but all years in my date column got changed to 2020.
Now I have two questions :
1] How can I change all 2020 year to 2011 in my date
2] What do you think, why did this happen ?
You can use a query like this:
UPDATE table SET datefield=datefield - INTERVAL 9 year WHERE records you want to change
If you leave out the WHERE clause it changes ALL records in the table.