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 2005 Forums
 Transact-SQL (2005)
 Date only function

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-11-05 : 11:38:47
I try to use the code below to return date only but still has time portion 12:00:00 AM. How to get rid of time portion?

return dateadd(dd,0, datediff(dd,0,@DateTime))

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-11-05 : 11:50:12
You can use CONVERT() function to cut the time portion but I will suggest to use front-end's formatting features to do this.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-11-05 : 12:02:18
I knew how to use convert function but I do not want to store date in text data type and I do not want to modify many front app codes as well.
Can anyone give me a point?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-11-05 : 12:19:37
>> I do not want to store date in text data type
A datetime contains the time - it's how the client converts it to character that matters.
If you have a client that can't convert to remove the time then you can't deliver it a datetime datatype.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Scott.Thornburg
Starting Member

10 Posts

Posted - 2007-11-05 : 21:10:46
OK, I agree with the others to let your client handle formatting. Having said that, here's one method to achieve your goal at the Sql LEVEL:


select convert(varchar(10), getdate(), 121)

Returns 2007-11-05

Look up the Books Online topic "CAST and CONVERT" for other possible formats.


Scott Thornburg
Go to Top of Page
   

- Advertisement -