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


source to share





All Articles