reynaldio
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
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',
What is wrong? How do i convert date from TDateTime to the date that Database will understand.
field type in database is TimeStamp
Thanks
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(TSQL TimeStamp( tstamp));
d := TimeStampToStr(v);
MessageDlg(d, mtConfirmation, [mbOK], 0);
end;
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(TSQL
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
Please see:
https://www.experts-exchange.com/questions/23314218/error-received-if-both-field-timestamp-in-a-table.html
ASKER
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
i finally got it solved. all i need to do is give the right formatting
d := FormatDateTime('yyyy-MM-dd
i'll give you the points anyway for your efforts.
thanks alot steve bay
ASKER
thanks :)
https://www.experts-exchange.com/questions/23314229/how-to-convert-timestamp-to-datetime.html