SEARCH
Archive for March, 2009
Combining Date and Time in SQL Server
Posted in: Programming by Steve on March 5, 2009
I have been working with Log Parser to go through IIS data from the last week. In working with it, I found that the queries I wanted to run were a little obscure to me, and not having time to mess around with learning a new query language, I just imported the data into SQL.
The W3C logs store the date and time in separate columns, and for one of my queries, I wanted to combine the date part with the time part to create a single datetime field.
So here’s my function that I created:
CREATE FUNCTION [dbo].[CombineDateTime](@dtDate DATETIME, @dtTime DATETIME) RETURNS DATETIME AS BEGIN RETURN @dtDate + CONVERT(CHAR(8), @dtTime, 108) END
Hope this helps!