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 |
|
notes4we
Yak Posting Veteran
90 Posts |
Posted - 2008-09-25 : 15:20:33
|
| Hello Friends,I have a table named Table1 and a column named CreationTime.CreationTime has the datatype as datetime.It gives the output as mm/dd/yyyy hh:mm:ssBut I want the output as hh:mm:ssI am aware that I can use CAST or CONVERT function, but I am not getting a proper syntax for the same.I would appreciate if anyone of you could help me to get the current syntax for what I wish to achieve. Thank you,notes4we |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-09-25 : 15:28:52
|
| SELECT CONVERT(varchar(8),CreationTime,108)FROM Table1will return what you want to the front end |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
notes4we
Yak Posting Veteran
90 Posts |
Posted - 2008-09-25 : 16:19:14
|
| Thank you Jimf. It works. |
 |
|
|
notes4we
Yak Posting Veteran
90 Posts |
Posted - 2008-09-25 : 16:22:40
|
| Tkizer, I have Excel as my source and SQL as my destination. I am using SSIS. I just wanted to use this for the views that I will be creating. And it is working fine. I do not understand why did you want me to avoid using it.Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 01:11:58
|
quote: Originally posted by notes4we Tkizer, I have Excel as my source and SQL as my destination. I am using SSIS. I just wanted to use this for the views that I will be creating. And it is working fine. I do not understand why did you want me to avoid using it.Thanks.
Because SQL Server is a db engine and formating is not a purpose of it. You should be trying to do format stuffs in your front end application as long as you can do it there.Even if you store it as datetime datatype with both date and time part you can easily do these formatting at you front end. And since the value remains as datetime in your db (table/view) you can use them for date manipulations also easily and make use of date functions also for it. By making it varchar using CONVERT you're losing out on these advantages, just for sake of getting value in your required format. |
 |
|
|
|
|
|