Monday, March 12, 2012

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:MI:SS 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:MI:SS 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 ?

thankshave you checked the manual? because it's in there

SQL Server recognizes date and time data enclosed in single quotation marks (') in these formats:
Alphabetic date formats (for example, 'April 15, 1998')
Numeric date formats (for example, '4/15/1998', 'April 15, 1998')
Unseparated string formats (for example, '19981207', 'December 12, 1998')|||what about time ? Can I insert a date with a time ?
Please help with an example .|||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?|||oh yes ... it is working....

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

Thanks r937.

No comments:

Post a Comment