I am wanting to populate a datetime field with data retrieved from 4 dropdowns month, day, year and hour 08:00 - 18:00.
I am having trouble joining them together in a format that the sql server recognises.
Printable View
I am wanting to populate a datetime field with data retrieved from 4 dropdowns month, day, year and hour 08:00 - 18:00.
I am having trouble joining them together in a format that the sql server recognises.
Use
YYYYMMDD HH24:Minute:second
There are other aphabetic and numeric formats available, check books online for a list.
Say for example your table is #x
Create table #x (date datetime)
declare @year varchar(4)
declare @Month varchar(4)
declare @Day varchar(4)
declare @Hr varchar(4)
declare @Min varchar(4)
set @year ='2003'
set @month ='08'
set @Day='11'
set @Hr='09'
set @Min='18'
Say all the values you retrieve from the front end are like above. then use the following statement to insert the datetime value.
--select @year+'-'+@Month+'-'+@Day+' '+ @Hr +':'+@Min
insert into #x select @year+'-'+@Month+'-'+@Day+' '+ @Hr +':'+@Min
--select * from #x
skhanal
worked a treat
thanks :)