Time value that is removed from datetime when I save it to MySQL

I am trying to store a datetime value in a MySQL database.

procedure TLocalDatabaseConnectionTests.TestSaveDateTime;
var
    StoredProc : TADOStoredProc;
    Connection : TADOConnection;
    dt : TDateTime;
begin
    StoredProc := TADOStoredProc.Create(nil);
    Connection := TADOConnection.Create(nil);
    try
        Connection.LoginPrompt := false;

        Connection.ConnectionString := String.Format
        (
            'DRIVER={%s}; SERVER=%s; DATABASE=%s; UID=%s; PASSWORD=%s;OPTION=3;',
            [
                'MySQL ODBC 3.51 Driver',
                'LOCALHOST',
                'DatabaseName',
                'Username',
                'Password'
            ]
        );

        StoredProc.Connection := Connection;
        StoredProc.ProcedureName := 'TestDate';

        StoredProc.Parameters.Clear;

        with StoredProc.Parameters.AddParameter do
        begin
            Name := String('@TheDate');
            DataType := TFieldType.ftDateTime;
            Direction := TParameterDirection.pdInput;
        end;

        dt := EncodeDateTime(1995, 12, 13, 13, 30, 1, 1);
        StoredProc.Parameters.ParamByName('@TheDate').DataType := TDataType.ftDateTime;
        StoredProc.Parameters.ParamByName('@TheDate').Value := TDateTime(dt);

        StoredProc.ExecProc;

    finally
        FreeAndNil(Connection);
        FreeAndNil(StoredProc);
    end;
end;

      

Here is the stored procedure

CREATE DEFINER=`root`@`localhost` PROCEDURE `TestDate`(TheDate DateTime)
BEGIN
    INSERT INTO new_table (idnew_table)
    VALUES (TheDate);
END

      

The problem is that time is always off.

date

I cannot explain why this

schema

The column is indeed defined as DateTime

, notDate

+3
mysql stored-procedures delphi ado delphi-xe6


source to share


No one has answered this question yet

See similar questions:

five
Using datetime parameter with ADO (ODBC) loses time part

or similar:

2568
Should I be using the datetime or timestamp datatype in MySQL?
1112
What MySQL data type is used to store boolean values
777
How to set default value for MySQL Datetime column?
697
Finding duplicate values ​​in MySQL
431
Converting from MySQL datetime to another format with PHP
293
PHP date () format when inserting into datetime in MySQL
2
Need a simple example of using TAdoConnection to connect to the default MySql database
1
Hebrew encoding from MYSQL to ASP provides?
0
Data source name not found and specified default driver not specified (ODBC)
0
asp.net core 2 MySQL 3.51 ODBC driver needed?



All Articles
Loading...
X
Show
Funny
Dev
Pics