-
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
-
How do you convert it in your code?
-
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
-
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
-
Forum Rules
|
|