Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    51

    Unanswered: INSERT statement for datetime .

    In Oracle , v can use select and insert for a date column as below:

    for select :
    ----------------------------------------------------------------
    select A,to_char(CDATE,'DD-MM-YY:HH:MIS AM') from db.table1;

    for insert:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    insert into db.table1
    (A,CDATE)
    values
    ( 2, TO_Date('20/01/2005 11:08:33 PM', 'DD/MM/YYYY HH:MIS AM'));
    ----------------------------------------------------------------


    But How v can use datetime in MSSQL Server ?
    What are the corresponding select and insert statement in this ?

    Any one have idea in this ?

    thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    have you checked the manual? because it's in there

    SQL Server recognizes date and time data enclosed in single quotation marks (') in these formats:
    1. Alphabetic date formats (for example, 'April 15, 1998')
    2. Numeric date formats (for example, '4/15/1998', 'April 15, 1998')
    3. Unseparated string formats (for example, '19981207', 'December 12, 1998')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2003
    Posts
    51
    what about time ? Can I insert a date with a time ?
    Please help with an example .

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    have you tried anything yet?

    do you think this will work --

    insert into db.table1 (A,CDATE) values ( 2, '20/01/2005 11:08:33 PM' )

    or do you think this will work --

    insert into db.table1 (A,CDATE) values ( 2, '2005-01-20 23:08:33' )

    what do you think?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Dec 2003
    Posts
    51
    oh yes ... it is working.....

    insert into db.dbo.table1 (A,CDATE) values ( 2, '20-jan-2005 11:08:33 PM' )

    Thanks r937.

Posting Permissions

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