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
 General SQL Server Forums
 New to SQL Server Programming
 Date

Author  Topic 

varunm
Starting Member

25 Posts

Posted - 2006-09-21 : 13:28:05
Help me In date.


Its Urgent...

Remove time in datetime datatype,wheni select.Please if possible psot with example.

Thanks

Gopi Nath Muluka
Starting Member

22 Posts

Posted - 2006-09-21 : 13:33:37
see this
declare @dt datetime

set @dt=getdate()
select @dt
select convert(varchar,@dt,101)

Thanks,
Gopi Nath Muluka
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-21 : 13:44:23
Why did you post this question again when it was already answered here?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=72363

CODO ERGO SUM
Go to Top of Page

varunm
Starting Member

25 Posts

Posted - 2006-09-21 : 15:14:19
I got that,plese look into that

select convert(varchar,colname,101) from table
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-21 : 15:19:26
quote:
Originally posted by varunm

I got that,plese look into that

select convert(varchar,colname,101) from table



Not sure what you mean, but
select convert(varchar,colname,101)  from table
is not a good solution because it returns a character string, not a datetime.


This is a much better way to do this:
select DateAdd(day,DateDiff(day,0,Datecol),0) from table




CODO ERGO SUM
Go to Top of Page

Gopi Nath Muluka
Starting Member

22 Posts

Posted - 2006-09-21 : 17:19:45
Solution depends on the requirements, for only display purposes I 'll go with this

select convert(varchar,getdate(),101)
--09/21/2006

If the result is included in any other caliculations I 'll go for this

select DateAdd(day,DateDiff(day,0,getdate()),0)
--2006-09-21 00:00:00.000


Thanks,
Gopi Nath Muluka
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-09-21 : 17:32:15
If it's just for display purposes, then you should do the formatting in the presentation layer and not in T-SQL.

Tara Kizer
Go to Top of Page
   

- Advertisement -