When a column contains a Date field, the dataclip displays it. When the "Export/Share" link is clicked and XLS selected, the resulting Date column is treated like a TEXT column in XLS.
Changing the Format in XLS does not seem to have an effect on it.
Is there a proper format for export that will make it into a Date cell?
I have tried 'MM-DD-YYY', 'MM/DD/YYY' and left it as default display (which puts the date and time in the column).
None of these are "dates" in XLS.
Thanks
I have done some tests and I think dates are exported as YYYY-MM-DD.
I really don't have Excel installed on this computer right now, but I downloaded an xls file from dataclips and imported it on Googlesheets. Dates were correct without any conversion needed.
Hi I am a noob in VBA and I'm having a hard time getting this one solved. I have made a userform that has 4 textboxes that is inputed by dates. The problem is everytime i retrieve the said data from my worksheet the value/code of the date is displayed, not the date. For example if I add the date 12/21/2016, and then try to call it. It will display 42544. I'm using Excel 2013. I don't have the date picker thing however I used a customized one but still got the same result.
As mentioned, try to use .Text instead of .Value. If it doesn't help, be sure that the Cell with the date is formatted as a date. Also make sure that you declare your variables as Date(Dim abc As Date) in the code.
I must write mm-aaaa (06-2014 for example) in an Excel sheet, but each time I do so, Excel automatically changes my cell format to "personalised" and select a date format.
Writing the value and pressing enter changes the format to custom; changing the format back to General change the date to 41780, which is no good either.
I absolutely need to keep the "General" format and the date to be written as mm-aaaa because the file is then going to be read by a python script which I cannot change. How can I achieve this?
Special pasting as text didn't work.
However setting the cell format as text, writing in it then changing it back to standart worked
Countless times during the day I am copying and pasting records from SQL Server Management Studio to Excel.
My problem is that a DateTime value such as 8/23/2013 4:51:02 PM does not display correctly as shown in the image below even though it shows correctly in the function box.
Changing the datatype to ShortDate fixes the display issues, but it is tedious to do since I have lots of date fields to format. Since Excel and SQL Server are both Microsoft products one would expect that Excel would be able to correctly show the date field.
EDIT: So this appears to be a display issue with Excel. I copied my Management Studio results to Notepad and from there into Excel and I still get the same issue.
Copying 2013-08-23 16:52:11.493 from Notepad to Excel will display 52:11.5 (displaying minutes, seconds and rounded milliseconds).
Excel version is 2010.
Any ideas to simplify this?
I also had an issue with this problem simply copy and pasting DATETIME fields from SQL Management Studio to Excel for manipulation. Excel has the correct value of the DATETIME (even if the formatting is applied after the paste), but by default doesn't have a built in format to show the SQL DATETIME. Here's the fix:
Right click the cell, and choose Format Cells. Choose Custom.
In the Type: input field enter
yyyy-mm-dd hh:mm:ss.000
Reference: http://office.microsoft.com/en-us/excel-help/create-a-custom-number-format-HP010342372.aspx
I had the same problem as Andre. There does not seem to be a direct solution, but a CAST in the query that generates the data fixes the problem as long as you can live within the restrictions of SMALLDATETIME. In the following query, the first column does not format correctly in Excel, the second does.
SELECT GETDATE(), CAST(GETDATE() AS SMALLDATETIME)
Perhaps the fractional part of the seconds in DATETIME and DATETIME2 confuses Excel.
This is a very old post, but I recently encountered the problem and for me the following solved the issue by formatting the SQL as follows,
SELECT CONVERT (varchar, getdate(), 120) AS Date
If you copy the result from SQL Server and paste in Excel then Excel holds the proper formatting.
Found a solution that doesnt requires to remember and retype the custom datetime format yyyy-mm-dd hh:mm:ss.000
On a new cell, write either =NOW() or any valid date+time like 5/30/2017 17:35: It will display correctly in your language, e.g. 5/30/2017 5:35:00 PM
Select the cell, click on the Format Painter icon (the paint brush)
Now click on the row header of the column that you want to apply the format.
This will copy a proper datetime format to the whole column, making it display correctly.
I know it is too late to answer to this question. But, I thought it would still be nice to share how I sorted this out when I had the same issue. Here is what I did.
Before copying the data, select the column in Excel and select 'Format cells' and choose 'Text' and click 'Ok' (So, if your SQL data has the 3rd column as DateTime, then apply this formatting to the 3rd column in excel)
Now, copy and paste the data from SQL to Excel and it would have the datetime value in the correct format.
Although not a complete answer to your question, there are shortcut keys in Excel to change the formatting of the selected cell(s) to either Date or Time (unfortunately, I haven't found one for Date+Time).
So, if you're just looking for dates, you can perform the following:
Copy range from SQL Server Management Studio
Paste into Excel
Select the range of cells that you need formatted as Dates
Press Ctrl+Shift+3
For formatting as Times, use Ctrl+Shift+2.
You can use this in SQL SERVER
SELECT CONVERT(nvarchar(19),ColumnName,121) AS [Changed On]
FROM Table
Try the following:
Paste "2004-06-01 00:00:00.000" into Excel.
Now try
paste "2004-06-01 00:00:00" into Excel.
Excel doesn't seem to be able to handle milliseconds when pasting...
Here's a hack which might be helpful... it puts an apostrophe in front of the time value, so when you right-click on the output in SSMS and say "Copy with Headers", then paste into Excel, it preserves the milliseconds / nanoseconds for datetime2 values. It's a bit ugly that it puts the apostrophe there, but it's better than the frustration of dealing with Excel doing unwanted rounding on the time value. The date is a UK format but you can look at the CONVERT function page in MSDN.
SELECT
CONVERT(VARCHAR(23), sm.MilestoneDate, 103) AS MilestoneDate,
'''' + CONVERT(VARCHAR(23), sm.MilestoneDate, 114) AS MilestoneTime
FROM SomeTable sm
Here's a simple macro that can be run after pasting data from SSMS. It's easiest if you copy it to your PERSONAL.XLSB file and add a button to the Quick Access Toolbar or a new custom group/tab in the ribbon. Run the macro immediately after pasting while the data is still selected. It can also be run if a single cell is selected within the data - it will automatically select the current area before running (same as ctrl-a). To run the macro on only a subset of data, select the desired subset before running. It can handle the data including or excluding headers, but assumes there at at least 2 rows in the current area.
It efficiently tests each column to see if the first non-NULL value looks to be a date/time value in the strange format. If it is, it sets the entire column to the default system date/time format, even if your date format is 'd/m/y'.
Sub FixSSMSDateFormats()
'Intended for copied data from SSMS and handles headers included
'For selection or current area, checks each column...
' If the first non-NULL value is in strange time format, then change entire column to system date/time format
Dim values As Variant, r As Long, c As Long
If Selection.Count = 1 Then Selection.CurrentRegion.Select
values = Selection.Value
For c = 1 To UBound(values, 2)
For r = 2 To UBound(values, 1)
If TypeName(values(r, c)) = "Double" Then
If values(r, c) > 1 And Selection(r, c).NumberFormat = "mm:ss.0" Then
Selection.Columns(c).NumberFormat = "m/d/yyyy h:mm"
End If
Exit For
ElseIf values(r, c) <> "NULL" Then
Exit For
End If
Next
Next
End Sub
I've had this same problem for a while as I generate a fair number of ad-hoc reports from SQL Server and copy/paste them into Excel.
I would also welcome a proper solution but my temporary workaround was to create a default macro in Excel which converts highlighted cells to Excel's datetime format, and assigned it to a hotkey (Shift-Ctrl-D in my case).
So I open Excel, copy/paste from SSMS into a new Excel worksheet, highlight the column to convert and press Shift-Ctrl-D. Job done.
i've faced the same problem when copying data from ssms to excel. the date format got messed up. at last i changed my laptop's system date format to yyyy-mm-dd from yyyy/mm/dd. everything works just fine.
I have a .xls I need to convert to .csv
The file contains some date columns. The format on the date is "*14/03/2001" which, according to Excel means the date responds to regional date and time settings specified for the OS.
Opening in Excel you see:
20/01/2013
01/05/2013
Save as... CSV
Open in notepad:
01/20/2013
05/01/2013
I have temporarily fixed by setting date formats to "14/03/2001" (no *) but even some other custom formats with no *, like "d/mm/yyyy h:mm" get mangled when saved to CSV.
Although keeping this in mind http://xkcd.com/1179/
In the end I decided to use the format YYYYMMDD in all CSV files, which doesn't convert to date in Excel, but can be read by all our applications correctly.
You can save your desired date format from Excel to .csv by following this procedure, hopefully an excel guru can refine further and reduce the number of steps:
Create a new column DATE_TMP and set it equal to the =TEXT( oldcolumn, "date-format-arg" ) formula.
For example, in your example if your dates were in column A the value in row 1 for this new column would be:
=TEXT( A1, "dd/mm/yyyy" )
Insert a blank column DATE_NEW next to your existing date column.
Paste the contents of DATE_TMP into DATE_NEW using the "paste as value" option.
Remove DATE_TMP and your existing date column, rename DATE_NEW to your old date column.
Save as csv.
Change the date and time settings for your computer in the "short date" format under calendar settings. This will change the format for everything yyyy-mm-dd or however you want it to display; but remember it will look like that even for files saved on your computer.
At least it works.
You need to do a lot more work than 1. click export 2. Open file.
I think that when the Excel CSV documentation talks about OS and regional settings being interpreted, that means that Excel will do that when it opens the file (which is in their "special" csv format). See this article, "Excel formatting and features are not transferred to other file formats"
Also, Excel is actually storing a number, and converting to a date string only for display. When it exports to CSV, it is converting it to a different date string. If you want that date string to be non-default, you will need to convert your Excel cells to strings before performing your export.
Alternately, you could convert your dates to the number value that Excel is saving. Since that is a time code, it actually will obey OS and regional settings, assuming you import it properly. Notepad will only show you the 10-digit number, though.
If you use a Custom format, rather than one of the pre-selected Date formats, the export to CSV will keep your selected format. Otherwise it defaults back to the US format
Place an apostrophe in front of the date and it should export in the correct format. Just found it out for myself, I found this thread searching for an answer.
A not so scalable fix that I used for this is to copy the data to a plain text editor, convert the cells to text and then copy the data back to the spreadsheet.
Change the date range to "General" format and save the workbook once, and change them back to date format (eg, numberformat = "d/m/yyyy") before save & close the book. savechanges parameter is true.
You can send your date to excel not like the "date" but like just a "string" with empty space at the start and end of the string.
Your problem is happening due to excel see your '11/02/2023' like a date, but you can hack it and change this date to a simple string like ' 11/02/2023 '.
Old: '11/02/2023'
New (solution): ' 11/02/2023 '