excel format date for mysql - mysql

My excel sheet has the following format : dd/mm/YYYY
ex: 24/10/2010 (european format)
and my mysql needs: YYYY-mm-dd (US format)
How can I format the date in Excel to have this US format ?
I tried with cell format, but I don't have the desired format
Regards

Here's how you can find this Number format in Excel:
Go to Format Cells and then the Number tab.
Select Date
Change the Locale to English (U.K.)
The fifth item on the list (on my U.S. version of Excel) is the format you're looking for.
Hope that helps!

For the hours, minutes and second
go in the custom category and enter this :
yyyy-mm-dd hh:mm:ss

Use the text function -- assuming that the date to be converted was in cell A1, =TEXT(A1,"YYYYMMDD") will get your data into a format that mysql will understand as a date.

There are many solutions, but I reformat the dates for mysql using this formula (assuming your date is in cell E2):
=YEAR(E2)&"-"&RIGHT(TRIM(100+MONTH(E2)),2)&"-"&RIGHT(TRIM(100+DAY(E2)),2)

Related

How to convert a text date into the short date format in excel

I have a database of dates that I need to map to another table in my MySQL database. The format of one table is listed as:
Dec 01 2020
And the other is listed as:
12/01/2020
My plan is to take all the text dates from table 1, convert to short date in excel, create a new table in MySQL, then re-map them to the short date in table 2. How can you convert the text date in excel so that it matches the format of the short date (12/01/2020)? I have tried using text to columns and other date functions in excel but have had no luck. Thanks in advance!
One can use REPLACE to place a , after the day number and Excel will then be able to convert it to a date. Then Simply format it as desired:
=--REPLACE(A1,7,0,",")

Format Date field in XAMPP SQL database to german layout (dd.mm.yyy) [duplicate]

I have a table in excel (CSV) which I am importing into phpmyadmin.
the cells show the date fine such as: 09/11/2012 0:00
The cell format is "custom"
when I import the table into phpmyadmin, all the dates turn to: 0000-00-00 00:00:00
What is the correct way to put them in excel so that I can import them into the database.
And how can I convert them to the correct format?
Format your excel dates into the format php accepts. E.g. yyyy-mm-dd h:mm:ss
In excel use the following steps:
Right click the column heading that contains the dates.
Select Format Cells
Click the "Custom" category
Paste "yyyy-mm-dd h:mm:ss" in the input box.
*. Save the document.
In php SQL query, make sure to set this column to date in anycase if php side is going to treat the date as a string.
You may use : ‘STR_TO_DATE(#date, '%Y-%c-%e %H:%i:%S')‘
I had this problem and thought I formatted them to format YYYY-MM-DD. They were displayed that way, but in the Formula bar it was still in DD/MM/YYYY format.
So I actively changed the date with:
=YEAR(A1)&"-"&IF(MONTH(A1)<10;"0";"")&MONTH(A1)&"-"&IF(DAY(A1)<10;"0";"")&DAY(A1)
And then copied the values of these cells to replace the original ones...

Copy formatted date from excel to notepad

I have extracted some data from mysql table a to excel. Now I have to create insert queries to insert into table b. In the table it has more than million records. Now in excel file, dates are converted into number. I have formatted the number to yyyy-mm-dd hh:mm:ss as required by mysql. But in insert query it remain number. Check the image as well.
image link:
http://s8.postimg.org/6g8fvf851/Capture.png
please tell me how can i copy the formatted date into notepad or sql.
In short, you should use text function to convert excel date to string.
=text(B2, "yyyy-mm-dd hh:mm:ss")
You can use this expression in your concatenate function or convert the dates to string representation, then use them in your formula.
Excel uses number to represent date. 0 means 1900-01-00 which is not exists. 1 means 1900-01-01. 1/24 means 1 hour, 1/24/60 means 1 minute and 1/24/60/60 means 1 second. You can check it by entering expression =1+1/24+1/24/60+1/24/60/60 in a cell then change its format to yyyy-mm-dd hh:mm:ss. It will show 1900-01-01 01:01:01.

MS Excel : How to get the changed date format when exporting as csv?

I have a MS Excel file in which a column contains date in the format m/d/yyyy and mm/dd/yyyy. I wanted all these dates to be imported in to a MySQL table.
So in MS Excel, I changed the cell format to custom date 'yyyy-mm-dd' and everything looked fine in the excel columns. When I exported it as .csv, all dates were in the original format i.e., m/d/yyyy and mm/dd/yyyy but not as 'yyyy-mm-dd'.
Please help me in this regard. Thank you!
Like David mentioned, you may have to replace the text before importing it to the MySQL table. You can try this formula:
=TEXT(A2,"yyyy-mm-dd")
And copy down. Then do a copy->Paste Values into the original date column. Then delete the temporary column with the Text() formula.
Try importing it after you replace the text. It should work out.

using excel dates for importing into phpmyadmin sql

I have a table in excel (CSV) which I am importing into phpmyadmin.
the cells show the date fine such as: 09/11/2012 0:00
The cell format is "custom"
when I import the table into phpmyadmin, all the dates turn to: 0000-00-00 00:00:00
What is the correct way to put them in excel so that I can import them into the database.
And how can I convert them to the correct format?
Format your excel dates into the format php accepts. E.g. yyyy-mm-dd h:mm:ss
In excel use the following steps:
Right click the column heading that contains the dates.
Select Format Cells
Click the "Custom" category
Paste "yyyy-mm-dd h:mm:ss" in the input box.
*. Save the document.
In php SQL query, make sure to set this column to date in anycase if php side is going to treat the date as a string.
You may use : ‘STR_TO_DATE(#date, '%Y-%c-%e %H:%i:%S')‘
I had this problem and thought I formatted them to format YYYY-MM-DD. They were displayed that way, but in the Formula bar it was still in DD/MM/YYYY format.
So I actively changed the date with:
=YEAR(A1)&"-"&IF(MONTH(A1)<10;"0";"")&MONTH(A1)&"-"&IF(DAY(A1)<10;"0";"")&DAY(A1)
And then copied the values of these cells to replace the original ones...