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 |
|
tschacherl
Starting Member
2 Posts |
Posted - 2012-01-23 : 17:33:23
|
| I have a table using the datetime data type and I'm trying to query based on just the time. For example, I have a table of shows and there are two shows that are named the same but they are at different times. One is at 7pm and the other at 8:30pm. Everything else is the same between the shows and both shows happen every day, which means I actually have lots of records for the two shows. One for each show each day for six months. Thus when I want to query on say the early show, I have no way to differentiate it from the late show because I'm unable to query just on the time part of the datetime field that contains the date and time of the show. This is running on MS SQL server 2005. Any suggestions? Thanks in advance. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tschacherl
Starting Member
2 Posts |
Posted - 2012-01-24 : 16:04:53
|
| Thanks tkizer, that's what I was looking for. I thought I had tried it before but this is what I got to work...select *,convert(varchar(10), eventDate, 108) as eventTime from [database].[dbo].[table] WHERE eventAct = 'show name' and convert(varchar(10), eventDate, 108) = '19:30:00'Of course I didn't need the "as eventTime" part but I just wanted to see what I was comparing too as I was getting messed up before by using the .000 part of the time. It's not part of the 108 format. I'm sure you know all this but I thought this might be useful for others with a similar question. Thanks for your help. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|