Solved

Error Update TimeStamp Field

Posted on 2008-06-12
7
479 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 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

24 Experts available now in Live!

Get 1:1 Help Now