Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Can SQL return just the Date?

Author  Topic 

ronmc
Starting Member

12 Posts

Posted - 2006-03-30 : 13:57:45
We have a fairly large application that has been converted from the DOS days and is now running on SQL. In our application, we will get data from the server by running a stored procedure or a pass-through statement and get any date-time field back by doing something like:

convert(varchar,oadata.date_, 101) as date_

This is ok for removing the time (which we don't always want to display to the user), but when we put this data into a grid, we allow the user to sort by any column. Of course, since we converted the date into a string, it sorts as a string. This is not good when dates span years.

Is there any way to bring back just the date from SQL, without having to convert it to a string?

I know that the presentation layer should handle this, but our specific language does not handle it very well.

Any takers?

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-03-30 : 14:08:02
This will set the time to 00:00:00.000 (midnight):

dateadd(dd,datediff(dd,0,MyDate),0)


CODO ERGO SUM
Go to Top of Page

ronmc
Starting Member

12 Posts

Posted - 2006-03-30 : 15:28:10
Ummm, almost there. The problem is that we don't want to display the time (even 00:00:00), at the presentation layer. I wish our program handled date times better, but it does not unfortunately.

Thanks tough.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-03-30 : 15:31:01
Presentation issue should be done in the presentation layer or try : SELECT CONVERT(varchar(10), getdate(), 101)


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

ronmc
Starting Member

12 Posts

Posted - 2006-03-30 : 16:02:09
Thank you. I just figured out how to make it work in my presentation layer.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-31 : 00:42:41
>>I just figured out how to make it work in my presentation layer.

Thats good
Formation should be done there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -