Results 1 to 4 of 4

Thread: Date conversion

  1. #1
    Join Date
    Sep 2003
    Posts
    30

    Angry Date conversion

    I have a datetime field in a table and I have to insert this datatime data into antoher table. In my insert statement I convert the datetime field into varchar and then insert it into the second table.

    The date field in the original table is : 2/2002/13 3:58:12 PM
    but in the destination table i get: 2/2002/13 3:58:00 PM

    I lose the seconds in the conversion, i think

    Whats the best way to preserve to the datetime field during transfer?

    thanks

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    How do you convert it in your code?

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    Why do you want to convert in the first place?


    Example:

    create table tbl1 (date datetime)
    create table tbl2 (date datetime)

    insert into tbl1 select '10/28/2003 10:45:00'
    insert into tbl1 select '10/28/2003 10:45:15'
    insert into tbl1 select '10/28/2003 10:45:00'
    insert into tbl1 select '10/28/2003 10:49:45'
    insert into tbl1 select '10/28/2003 10:59:59'

    insert into tbl2 (date) select date from tbl1

    select * from tbl1
    select * from tbl2

  4. #4
    Join Date
    Sep 2003
    Posts
    30
    It works well with:
    convert(char(26),@datetime,9)

    this will preserve the format mon dd yyyy hh:mi:ss:mmmAM (or PM).

Posting Permissions

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