大家好,我想获取格式为2014-01-01的end_date
我想对我在end_date中的内容进行查询时使用减法方法(该方法有效),因此我可以使用if方法来查看是否已经支付了他们的费用,但是我不知道如何使查询读取end_date并将其与日期进行比较
这是我目前的代码:
string myConnection = "server=****;user=****;database=***;port=3306;password=***;";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand SelectCommand = new MySqlCommand("SELECT end_date FROM username = '" + this.username_txt.Text + "'", myConn);
MySqlDataReader myReader;
myConn.Open();
DateTime endDate = get end_date from query here???;
var DaysLeft = (endDate.Date - now.Date).Days;
MessageBox.Show(""+ DaysLeft);
最佳答案
这样的事情应该会让您入门:
string myConnection = "server=****;user=****;database=***;port=3306;password=***;";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand cmd = conn.CreateCommand();
SELECT DATEDIFF(NOW(), your_date)
cmd.CommandText = "SELECT DATEDIFF(NOW(), end_date) FROM TABLE WHERE username = '" + this.username_txt.Text + "'";
myConn.Open();
MessageBox.Show(cmd.ExecuteScalar());
将
TABLE
更改为表的名称。除此之外,我认为它应该可以工作。