Page 1 of 1

[Solved] GetDateTime delivers 01.01.0001 00:00:00

Posted: Mon 18 Nov 2013 09:53
by uglykidkap
Hi Guys,

I am using the current version of dotConnect for MySQL. (8.1.36.0)

In my database I got a datetime column with the value: 0000-00-00 00:00:00

If I query this value from my .Net application I get the value: 01.01.0001 00:00:00

Code: Select all

                MySqlConnection Connection = new MySqlConnection();
                Connection.UserId = "test";
                Connection.Password = "test";
                Connection.Host = "test";
                Connection.Database = "testdb";
                Connection.Open();


                if (Connection.State == System.Data.ConnectionState.Open)
                {
                    string query = string.Format("select sessions_enddate from sessions where sessions.sessions_id = 48;");

                    MySqlCommand myCommand = new MySqlCommand(query, Connection);

                    MySqlDataReader myReader = myCommand.ExecuteReader();

                    // Always call Read before accessing data. 
                    while (myReader.Read())
                    {
                        // returns 01.01.0001 00:00:00
                        Console.WriteLine(myReader["sessions_enddate"].ToString());
                        
                        // returns 01.01.0001 00:00:00
                        DateTime EdnDate = myReader.GetDateTime(myReader.GetOrdinal("sessions_enddate"));
                    }

                    // always call Close when done reading. 
                    myReader.Close();

                    Console.ReadKey();
                }

Why?

Best regards,

Philipp

Re: GetDateTime delivers 01.01.0001 00:00:00

Posted: Mon 18 Nov 2013 15:26
by Pinturiccio
uglykidkap wrote:In my database I got a datetime column with the value: 0000-00-00 00:00:00
According to MySQL documentation '0000-00-00 00:00:00' is the result of automatic conversion of an illegal DATETIME value to the “zero” value. And the supported range for DATETIME type is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. For more information, please refer to http://dev.mysql.com/doc/refman/5.0/en/datetime.html
uglykidkap wrote:If I query this value from my .Net application I get the value: 01.01.0001 00:00:00
The minimal value for .NET Framework DateTime type is 00:00:00.0000000, January 1, 0001. For more information, please refer to http://msdn.microsoft.com/en-us/library ... 10%29.aspx
uglykidkap wrote:Why?
When reading an invalid DATETIME value, there are two possible ways. The first is to throw an exception. The second is to replace the invalid value with some other value. We decided to choose the second option and to replace invalid DATETIME values with the minimal value of the DateTime object.

Re: GetDateTime delivers 01.01.0001 00:00:00

Posted: Wed 20 Nov 2013 09:16
by uglykidkap
Hi Pinturiccio,

good to know, thank you for your detailed explanation!

Best regards,

Philipp