SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Another DATETIME to DATE conversion question - getting just the DATE to display in Excel


Another DATETIME to DATE conversion question - getting just the DATE to display in Excel

Author
Message
rondad
rondad
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 27
Hi,

I have a different variant of the common question relating to conversion of DateTime variables in Excel to "Date Only."

I want to create a view in Excel 2008 that will be used by Excel users via MSQuery. Several of the fields in the view are DateTime values. The users also need to select/filter the query results by these DateTime fields.

So, there are issues with all of the "standard" approaches to this issue:

1. If I just include the DateTime field in the view, when it gets to Excel, it is displayed as Datetime (with the Time shown). The users then have to format the column as mm/dd/yyyy date format. Now this isn't the worst thing, but they use this view frequently, so they have to format the 4 date columns every single time they create a new spreadsheet.

2. If I use CONVERT, e.g.
Convert(nvarchar(10),j.[Creation Date],101) AS [Creation Date],

Then the result is converted to string, and you can't do a select/filter, e.g. you can't filter on "Creation Date" > 11/15/2010 - you will get all dates that begin with "11" as well as "12" regardless of year, e.g. you'll get dates like "12/1/2009" in the result set.

3. If I use CAST to type DATE, e.g.
CAST(j.[Creation Date] AS Date) As [Creation Date],

Then the user CAN select/filter correctly (the correct result set is returned). However, in Excel, the field is returned as string in format YYYY-MM-DD, e.g. 2010-12-15 and you can't set a format in Excel to change it to mm/dd/yyyy.


So, to Summarize:

1. I have fields of type DateTime in my view
2. Users have to be able to select in MSQuery based on a date range e.g. > 12/7/2010
3. I want the date to display in Excel as 12/07/2010 without having to reformat the column every time I create a new spreadsheet/query.

Is this possible?

Thanks in advance

Ron


dateadd(dd,datediff(dd, 0, getdate()), 0)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search