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.
Author |
Topic |
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:06:15
|
Hi All,How can I convert datetime to just date.Right now the records are like the following:2005-03-02 00:00:00I just want to display it as 2005-03-02I would prefer the datepart function. Or if it cannot work something else.Any help would be higly appreciated.Zee |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-08-02 : 11:09:41
|
this formatting shuold be done at the presentation layer.or you can use convert function:select convert(varchar(10), yourDateTimeColumn, 120)_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:12:53
|
spirit1,Thanks....Can I use datepart? If yes, how?.Thanks for your help. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-02 : 11:23:03
|
Datepart? Yes.SELECT CAST(DATEPART(YEAR, Col1) AS VARCHAR(4)) + '-' + RIGHT('0' + CAST(DATEPART(MONTH, Col1) AS VARCHAR(2)), 2) + '-' + RIGHT('0' + CAST(DATEPART(YEAR, Col1) AS VARCHAR(2)), 2)Datename? Yes.SELECT DATENAME(YEAR, Col1) + '-' + RIGHT('0' + DATENAME(MONTH, Col1), 2) + '-' + RIGHT('0' + DATENAME(YEAR, Col1), 2)Convert? Yes.SELECT CONVERT(CHAR(10), Col1, 120) E 12°55'05.25"N 56°04'39.16" |
 |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2007-08-02 : 11:31:15
|
Thanks :D |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-03 : 03:33:44
|
quote: Originally posted by zeeshan13 spirit1,Thanks....Can I use datepart? If yes, how?.Thanks for your help.
Is there any specific reason?MadhivananFailing to plan is Planning to fail |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-08-03 : 14:27:23
|
quote: Originally posted by madhivanan
quote: Originally posted by zeeshan13 spirit1,Thanks....Can I use datepart? If yes, how?.Thanks for your help.
Is there any specific reason?MadhivananFailing to plan is Planning to fail
Sometimes, it's fun to do things the hard way.CODO ERGO SUM |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-06 : 02:37:44
|
<<Sometimes, it's fun to do things the hard way.>>Yes it is MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|