繁体   English   中英

是否获得当前日期与列中包含的日期之间的天数,小时数和分钟数的差异?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM