| Author |
Topic |
|
ya3mro
Starting Member
37 Posts |
Posted - 2006-06-15 : 05:59:27
|
| in my example i have table has column called DATEand when i do :Select Distinct Date from tablename i have :: 09/06/2006 07:00:00 09/06/2006 10:00:00 10/06/2006 04:00:00 10/06/2006 07:00:00 10/06/2006 10:00:00 11/06/2006 04:00:00 11/06/2006 07:00:00 11/06/2006 10:00:00 and i want to Select Distinct Date without Time to be showed as 09/06/2006 10/06/2006 11/06/2006 PLZ Help MeHow I Came To Islam? http://english.islamway.com |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-15 : 06:07:23
|
| Where do you want to show the converted dates?If you use Front end application, do formation thereOtherwise look for Convert function in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-15 : 06:20:57
|
[code]select dateadd(day, datediff(day, 0, datecol), 0)[/code] KH |
 |
|
|
ya3mro
Starting Member
37 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-15 : 07:11:48
|
[code]select distinct dateadd(day, datediff(day, 0, datecol), 0)[/code] KH |
 |
|
|
ya3mro
Starting Member
37 Posts |
Posted - 2006-06-15 : 07:28:29
|
| thanx KHtan and i also try this ::SELECT DISTINCT CAST(SUBSTRING(CAST(DateCol AS varchar), 0, 10) AS Datetime) AS DateResultFROM tableNamebut which is better this OR select dateadd(day, datediff(day, 0, datecol), 0)How I Came To Islam? http://english.islamway.com |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
sqldev80
Yak Posting Veteran
68 Posts |
Posted - 2006-06-15 : 12:27:49
|
| SELECT CONVERT(VARCHAR(10), GETDATE(), 126)you can put the coulmn name instead of the getdate()Select Distinct CONVERT(VARCHAR(10), GETDATE(), 126) from table nameHope this works. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-16 : 02:42:49
|
quote: Originally posted by ya3mro thanx KHtan and i also try this ::SELECT DISTINCT CAST(SUBSTRING(CAST(DateCol AS varchar), 0, 10) AS Datetime) AS DateResultFROM tableNamebut which is better this OR select dateadd(day, datediff(day, 0, datecol), 0)How I Came To Islam? http://english.islamway.com
The second method is best to use if there is index on the date columnIf you use front end application format the date thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|