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 |
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2009-09-24 : 09:33:37
|
| i have a simple question:i use smalldatetime to hold time, it gives date plus time but i only need time of format hh:mm, how can i filter this? same thing to date, i just want dd:mm:yy. thanks in advance. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-24 : 09:51:26
|
| If it's just a display issue, it should be done in the front end, butselect convert(char(5),getdate(),108)will do the trick. Note -- this is no longer a date or a time, it is now a stringJimEveryday I learn something that somebody else already knew |
 |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2009-09-24 : 10:07:10
|
| thanks but i still don't get it. what if i want to convert a field called BeginTime? thanks. |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-24 : 10:14:43
|
| Select convert(varchar(5), beginTime, 108)[ /fail at humor] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-24 : 10:20:03
|
| You put the field you wish to convert into the Convert(VarChar(*length of characters you want it to hold*) , Fieldname_Goes_Here, *Format Number goes here*)[ /fail at humor] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-24 : 10:25:18
|
quote: Originally posted by allan8964 i have a simple question:i use smalldatetime to hold time, it gives date plus time but i only need time of format hh:mm, how can i filter this? same thing to date, i just want dd:mm:yy. thanks in advance.
Where do you want to show the data?MadhivananFailing to plan is Planning to fail |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-24 : 11:35:19
|
| SUBSTRING(Convert(Varchar(15), beginTime, 106), 13, 16)orSUBSTRING(Convert(Varchar(15), beginTime, 112), 11, 14)Would show the time if thats what you are after?[ /fail at query] |
 |
|
|
|
|
|
|
|