Link to home
Start Free TrialLog in
Avatar of reynaldio
reynaldioFlag for Indonesia

asked on

Error Update TimeStamp Field

Hi all,

i get this error when trying to execute query - SQL Server Error: conversion error from string "6/13/2008 1:03:12 AM".

This is my code

d := DateTimeToStr(Now);

Format('EXECUTE PROCEDURE SP_UPDATESERIALNO(%s, %s)',
        [QuotedStr(SerialNo),  QuotedStr(d)]);

and the query will look like this.

EXECUTE PROCEDURE SP_UPDATESERIALNO('12345', '6/13/2008 1:03:12 AM')

What is wrong? How do i convert date from TDateTime to the date that Database will understand.
field type in database is TimeStamp

Thanks
Avatar of SteveBay
SteveBay
Flag of United States of America image

Avatar of reynaldio

ASKER

Thanks stevevbay for your quick response.

I see the link you gave me. but what is I have TDateTime and i want to update field that is TimeStamp.

i tried this but i get invalid argument error


var
  v: Variant;
  tstamp: TSQLTimeStamp;
  d: String;
begin
  tstamp := datetimetosqltimestamp(now);
  v := VarSQLTimeStampCreate(TSQLTimeStamp(tstamp));
  d := TimeStampToStr(v);
  MessageDlg(d, mtConfirmation, [mbOK], 0);
end;
You cannot update a TimeStamp field in MSSQL. It's an automatic field.
Please see:
https://www.experts-exchange.com/questions/23314218/error-received-if-both-field-timestamp-in-a-table.html
hi,

i dont use MSSQL, i use firebird. sorry i didnt mention it earlier.
i can update my timestamp field if i update it from dataset.

something like this.

dsMYDATEFIELD.AsDateTime := Date;
ds.ApplyUpdates(0);

but if i want to update with execsql like i mention ealier, i got that error.
any other suggestion?
ASKER CERTIFIED SOLUTION
Avatar of SteveBay
SteveBay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

i finally got it solved. all i need to do is give the right formatting
d := FormatDateTime('yyyy-MM-dd hh:mm:ss', Now);

i'll give you the points anyway for your efforts.

thanks alot steve bay
thanks :)