Solved

sql views and dates

Posted on 2013-06-26
4
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 49

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 49

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 49

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

617 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