[英]Getting the difference in days, hours and minutes between current date and the date contained in the column?
我有一個帶有datagridview的應用程序,我直接從數據庫綁定信息,我有一個名為DateTime類型的deadline
的列,該列保存期限的日期。
在我的C#應用程序中,我要遍歷datagridview中的所有行,並獲取包含截止日期的特定列,然后對其進行更新,例如:
public void reformatDates() {
string endDate = null;
foreach (DataGridViewRow rw in dataGridView1.Rows)
{
endDate = rw.Cells[5].Value.ToString();
rw.Cells[5].Value = getCountDown(endDate);
}
}
函數getCountDown(DateTime endDate)
以天,小時和分鍾為單位獲取倒數。
一切都按預期工作,但是隨着我在所有行中進行迭代,如果我有很多行說5000行,該怎么辦。 我是否需要遍歷所有這些對象並更新每個單元格?
我用來綁定數據庫信息的函數是Bind(string sqlquery),我現在這樣調用它:
Bind("SELECT statut,title,deadline FROM taches WHERE 1");
是否有某種方式可以直接從數據庫中獲取倒計時(以天,小時和分鍾為單位),我的意思是這樣的
偽代碼:
Bind("SELECT statut,title,(DateNow-deadline) FROM taches WHERE 1");
任何幫助將不勝感激。 謝謝
如果我理解正確,這就是您想要的:
Bind("SELECT statut,title,TimeDiff(sysdate(),deadline) FROM taches WHERE 1");
完整參考: https : //dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_sysdate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.