Copy formatted date from excel to notepad - mysql

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.

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...

Import CSV to SQL - Date format issues: Zeroes

I'm trying to import CSV data into MySQL database. I have four Date fields. when the import finishes, all my dates are zeroes: .
I've set the date format to DATE in Excel prior to saving it as CSV. I've set the table field as DATE in MySQL.
I'm using phpMyAdmin to do the import.
Mysql only excepts dates in YYYY-MM-DD format.
The Date format in excel is 06/09/2015. Thus, not in the format that mysql is expecting. You must change this to a format that is accepted in mysql otherwise all your date fields will appear as 0000-00-00.
In order to change the date format in excel: right click on the top cell. Choose format cells from the drop down list. change the local to something like 'Afrikans'. Choose the format that looks like 2001-03-14. Use the top cell to fill down. Then save the document.
Just a quick note: Excel sometimes tries to do too much and will revert this column back to a the English(U.S) default time zone. So, if you plan on doing more editing make sure that the column has not reverted back.
Here is a link to more string literals on dev.mysql.

Convert Date to a number in mysql (Like how a date converts in Excel)

What is the correct function to use when i want to convert a date to a number. Like when you enter a date in excel for example (now()) and then it will show the date but when you click on the number format it will show you a number.
I tried to use Unix timestamp but its not exactly the output i was looking for.
The date i entered is today's date
=now()
and the output i was hoping to get is
42146
what's the correct function to get this result in mysql?
Thank you
Microsoft Excel bases date serial numbers from Jan 1, 1904 or from Jan 1, 1900 (depends on the setting in the workbook.)
To generate a date "serial number" similar to what Excel uses, just calculate the number of days between NOW() (or whatever date you want to convert), and the base date. For example:
SELECT DATEDIFF(NOW(),'1900-01-01') AS excel_serial_date_1900
(You might need to add 1 or subtract 1 to get the exact same value that Excel uses, I've not tested that.) If your Excel workbook is using the 1904 based serial date, use '1904-01-01' as the base date in the expression.
Note: the DATEDIFF function returns integer number of days, operates only on the "date" portion, and doesn't include any fraction of a day.
Reference: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff

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...