Solved

sql views and dates

Posted on 2013-06-26
4
217 Views
Last Modified: 2013-07-15
I have an sql view that I display on sharepoint using sharepoint data sources.

The field in my SQL view that I want to share is order by is called [date recorded]

The field date recorded is a datetime field and is stored using American formatting as that is the sql server default.

I can get the dates in british format by using this CONVERT(nvarchar, dbo.tblcustomerdetails.[Date Recorded],103 ) however then I cant order by the date as it is no longer a date.

If I try CONVERT(date, dbo.tblcustomerdetails.[Date Recorded],103 ) it still displays as American format.

Is there a way through either the SP data sources or SQL that I can get this to be a date still but displayed in English format.
0
Comment
Question by:CaptainGiblets
  • 3
4 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39277291
IF it really is a datetime field:
>>field date recorded is a datetime field and is stored using American formatting
sorry, that's not a correct impression
datetime information is stored as 2 integers - it is never stored by the format
what you 'see' isn't what is stored

you do NOT need to convert at all to properly order by that datetime field

select
-- use a format here to 'display' it in the fashion wanted
convert(varchar, thatField, 121) as displayDate -- 103, your choice
...
from whatever
order by
 thatField -- no conversion required here
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39277292
IF you are removing 'time' as part of the logic

select
-- use a format here to 'display' it in the fashion wanted
convert(varchar, thatField, 121) as displayDate -- 103, your choice
...
from whatever
order by
  -- no conversion required here
dateadd(day, datediff(day,0, [thatField] ), 0) -- use date functions to remove the time
0
 
LVL 6

Author Comment

by:CaptainGiblets
ID: 39277295
I have tried converting to varchar but then sharepoint will only treat it as a string.
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39277314
@CaptainGiblets sorry - didn't look at the asker's name - I just jumped in
(it's a hot button for me: the impression that dates are stored in a format)

I have to admit I really only know SharePoint as an end-user but:
 
try this?

convert(date,[thatField]) -- removes time
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now