Solved

Error Update TimeStamp Field

Posted on 2008-06-12
7
481 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
enhance the following code 3 37
How to Get Images From Server using App Tethering 11 39
firemonkey Android Listview Sort items 7 50
IIF in access query 19 24
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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