Results 1 to 4 of 4

Thread: inserting date and time

  1. #1
    Join Date
    Aug 2003
    Location
    Christchurch New Zealand
    Posts
    3

    Unhappy inserting date and time

    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.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Use

    YYYYMMDD HH24:Minute:second

    There are other aphabetic and numeric formats available, check books online for a list.


  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    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

  4. #4
    Join Date
    Aug 2003
    Location
    Christchurch New Zealand
    Posts
    3
    skhanal

    worked a treat

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •