Question : SQL Server - Date function to create a new date from date parts?

I am looking for a way in SQL Server to be able to create a new Date variable by explicitly declaring the year, month, day, hour, minute, second, etc.

Either that, or I want to be able to take a current date variable and and modify specific date parts by explicitly setting them to a specific integer.

Is there a function in SQL Server that will perform either of these tasks?

Answer : SQL Server - Date function to create a new date from date parts?

DECLARE @year VARCHAR(4) , @month CHAR(2), @Day CHAR(2) , @hr CHAR(2), @min CHAR(2) ,@Sec CHAR(2)
SELECT @Year = '2009', @month = '02', @Day = '01', @min = '10',  @hr= '01', @Sec = '34'

SELECT CAST (@Year+@month+@Day+' '+@hr+':'+@Min+':'+@Sec AS datetime )

SELECT DATENAME(year, '2007-06-01 12:10:30.123')
    ,DATENAME(month, '2007-06-01 12:10:30.123')
    ,DATENAME(day, '2007-06-01 12:10:30.123')
    ,DATENAME(dayofyear, '2007-06-01 12:10:30.123')
    ,DATENAME(weekday, '2007-06-01 12:10:30.123');
SELECT DATENAME(hour, '2007-06-01 12:10:30.123')
    ,DATENAME(minute, '2007-06-01 12:10:30.123')
    ,DATENAME(second, '2007-06-01 12:10:30.123');
Random Solutions  
 
programming4us programming4us