I've been producing a csv file from Salesforce Marketing Cloud. The date column is using two different date formats for seemingly random dates:
How can I stop it from doing this? I have also exported it from SFMC in a text format, and all the dates are in the same format in that file, but as soon as I convert it to CSV it puts them in this variety of formats. Can anyone help?
Excel tries to fix it for you. You should import into excel using the' Data Tab > Get External Data'. As you import make sure you select the correct date format for the column with your dates. ie MM/DD/YYYY h:mm:ss AM/PM.
Related
I'm experiencing an issue where when I import using SQL import, or ETL job, a CSV Excel type file into SQL that the dates are being converted or altered to something else.
I'm trying to ID a pattern but for example here are two date samples. before and after:
Before After
======= =======
30/01/2015 20/01/1930
11/09/2015 20/09/2011
Seems like the day number is being used to replace the year portion, and in first case century reverts to 19, and the original century portion is, in some cases, overwriting the day, if that makes sense?
I can't see why it would do this, none of the other files I had done this, and they were all Excel CSV files. They were transferred the same way to the same data mart from the same file location.
It's scary to think one file can suddenly do this with no error being raised, and just lucky it was spotted in the end reports.
Any thoughts greatly appreciated.
Thanks
Andrew
Depends on the SQL dialect you are using. For example, Mysql only accepts dates in YYYY-MM-DD format.
The Date format in excel is 06/09/2015.
To make sure everything is okay, just explicitly set the Date format in Excel.
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.
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...
I have used PHPExcel library to import an Excel file (.xlsx) and insert into MySQL. I'm facing two problems with the date field:
1- In the excel sheet I try to change the date format to the desired one. Upon saving, the cells show the format I need (yyyy/mm/dd) but when I double-click to edit them they again change back to how it was before (mm/dd/yyyy).
2- When the file is imported to MySQL through PHPExcel all the columns are inserted correctly except the date column which inserts 0000-00-00. The format in the Excelsheet is the same as in MySQL but it enters is all zeros.
Please help!
The value store in PHPExcel is an Excel serialized datetime value (a float, representing the number of days since 1/1/1900 or 1/1/9004 depending on whether Windows or Mac Calendar was used). Changing the format is simply changing the way this value is displayed.
You will either need to know in advance whether a cell contains a date, or test it using the PHPExcel_Shared_Date::isDateTime() method, and convert it appropriately. You can then either retrieve it using getFormattedValue() to return the value as a formatted string; or use the built-in conversion functions to convert it to a unix timestamp (PHPExcel_Shared_Date::ExcelToPHP()) or a PHP DateTime object (PHPExcel_Shared_Date::ExcelToPHPObject()) that you can then format using the standard PHP date formatting functions before using it in your MySQL INSERT/UPDATE statements.
Change the date format to yyyy-mm-dd, save the file as CSV and import that into your database.
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.
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...