How to compare time values in SQL Server 2005

The following query filters the results set based on the time value only

Select * From <Table Name>

Where  Convert(Varchar(8),<DateTime Field Name>,8) >= ‘<Time Value>’

In the above query it will compare a time value with the format of,

           hh:mm:ss

If you don’t want the seconds portion of it simply reduce the length of the converted field

ie. Convert(varchar(5),<DateTime Field Name>,8)      this will only return a time value with the format of,

        hh:mm

Happy coding!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s