Solved

sql views and dates

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

27 Experts available now in Live!

Get 1:1 Help Now