in

ASP.NET Weblogs

uber1024's WebLog

It's not hot wings and beer, but it's still okay

Combining date and time into one value in SQL Server

I have a project where I need to upload a date and a time seperately into SQL Server, yet they need to be in one field in the database.  Here is a sketch of the solution:

CREATE PROCEDURE zzz_JohnTest @StartDate datetime, @StartTime varchar(50)
 AS

declare @startdatetime datetime

declare @strDateTime varchar(200)

-- this next line converts the date parameter to a string in the format of "MM/DD/YYYY" and adds the time

select @strDateTime = Convert(varchar(100), @StartDate, 101) + ' ' + @StartTime

select @startdatetime = cast (@strDateTime as datetime)

select @startdatetime as StartDateTime
GO

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add