using MySql.Data.MySqlClient; //... MySqlCommand cmd = new MySqlCommand("SELECT order_date FROM orders WHERE order_id = @orderId", conn); cmd.Parameters.AddWithValue("@orderId", orderId); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DateTime orderDate = reader.GetDateTime(0); Console.WriteLine("Order date: " + orderDate.ToShortDateString()); }
using MySql.Data.MySqlClient; //... MySqlCommand cmd = new MySqlCommand("SELECT created_at FROM customers WHERE customer_id = @customerId", conn); cmd.Parameters.AddWithValue("@customerId", customerId); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { DateTime createdAt = reader.GetDateTime("created_at"); Console.WriteLine("Customer created at: " + createdAt.ToString()); }In this example, we have a SQL query that retrieves the created_at date from the customers table where the customer ID matches a specified value. We then use the GetDateTime method with a column name parameter to retrieve the value of the created_at column as a DateTime object. Package library: MySql.Data.MySqlClient