Solved

sql views and dates

Posted on 2013-06-26
4
222 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

735 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