Solved

Error Update TimeStamp Field

Posted on 2008-06-12
7
477 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:reynaldio
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 21772230
0
 
LVL 2

Author Comment

by:reynaldio
ID: 21772608
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;
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 21772708
You cannot update a TimeStamp field in MSSQL. It's an automatic field.
Please see:
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_23314218.html
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Author Comment

by:reynaldio
ID: 21772805
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?
0
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 21772862
Oh. That does make a difference. I should have remembered that from the the last issue you posted.
I am afraid that I can't help with Firebird issues - I never touch the stuff ;-)
0
 
LVL 2

Author Comment

by:reynaldio
ID: 21772944
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
0
 
LVL 2

Author Closing Comment

by:reynaldio
ID: 31466671
thanks :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now