i want to save date using inert query like insert into tablname(field1,f2) values('jan',"& format(system.date.now,"dd/MM/yyyy hh:mm ") so to give error that char will not be converted to date and time.plz help its urgent.the same problem is with select query toooooo.
Hi,
You should elaborate more about the problem here. Post your code and let us know the way you are inserting data into the database and the fields types
Regards
|||i want to insert in a data base some thing using this query:
insert into tble1(field1,field2) values('this some thing or data','"& syatem.now &"');
which kind of date it will store like this 24/05/2007 11:16 AM or 24/05/2007 .i want to store 24/05/2007 11:16 AM this one.i using format function of vb.net like format(system.date,"dd/MM/yyyy hh:mm tt") but it give me error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value".in the select statement also this problem occure. i also use thhe select query as
select * from tbl1 where pdate='"& format(variabledate,"dd/MM/yyyy hh:mm tt") &"'" and it also give me error "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value".this in acess work fine but in sql server give the above error.
|||
Hi,
please try something like following
Datetime dt = newDateTime(2007,6,18,13,56,30)); //year, month, day, hour, minute, seconds
thanks,
satish.
|||Hi there,
Use this command:
INSERT INTO TABLENAME (field1,field2) VALUES ('jan',getdate())
hope it helps you out,
gonzzas
|||
This is one of those difficult to answer questions because what you are trying to do is inheritly wrong. Datetime fields do not have a format. They represent a particular point in time. You can convert a datetime to and from a string with a specific format, but then it's no longer a datetime. You are trying to store a string with a format that sql server doesn't understand into a datetime field. SQL Server is attempting to covert your string into a real datetime so it can be stored, but the format isn't one it understands. Regardless of any of the correct formats you feed it, so long as it means the same point in time, ultimately it will get converted to the exact same number (Datetimes are internally represented by the number of days since the epoch, with the time portion being a fraction of a day).
|||Hi again,
Here is another example of a sql command that inserts a row in a table. One of the row fields has DATETIME datatype:
Dim strAsString ="insert into users (username,password,date) values ('username1','password1',convert(datetime,'18-06-2007 23:21:00',105))"
Dim commandAsNew SqlCommand(str, conn)Dim result = command.ExecuteScalar()
Where you see 105 it's the format chosen by me for this test. This format stores the data as dd-mm-yyyy hh:mm:ss
You can use another formats (do some light research on the subject, it should be enough) to meet your requirements: dd/mm/yyyy hh:mm:ss
gonzzas
|||
actually i solve the insert by using the query like
"insert into table tblname(f1,datef1) values('abc','"& system.datetime.now.tostring("MM/dd/yyyy hh:mm:ss") &"')"
but i still receiveing errors in select query that char conversion.
this stuff is doing in vb.net and sqlserver.
No comments:
Post a Comment