截断C#中的日期/时间时间戳

use*_*856 0 c# sql datetime casting

我想从dateTime字段中删除时间戳.

int[] projects = {11157, 11138};

protected void compare(System.Data.DataTable dt1, System.Data.DataTable dt2, int[] arr)
{
    differences.Columns.Add("ID", typeof(int));
    differences.Columns.Add("BRS Date", typeof(string));

    foreach (int value in arr)
    {
        DataRow[] result = dt1.Select("ChangeRequestNo = '" + arr +"' OR [GPP ID] = '" + arr + "'");
        string brs = "";
        string srs = "";
        if (result.Length > 1)
        {
            DataRow row1 = result[0];
            DataRow row2 = result[1];
            DateTime row1date = (DateTime)row1[2];
            DateTime row2date = (DateTime)row2[10];

            //Remove the Time stamp on the dateTime 
            //variable coming from the GPP Extract
            //row2date.cast(floor(cast(getdate() as float)) as datetime);

            if (row1date.Equals(row2date))
            {
                // find your Image control in the Row
                //Image image = ((Image)differences.Rows[1].FindControl("img"));
                // set the path of image
                //img.ImageUrl = "path of image";  
                brs = "True";

            }
Run Code Online (Sandbox Code Playgroud)

这个问题可能是通过SQLserver问的,但是对C#不起作用,除非我做错了(最有可能):

如何在SQL Server中截断日期时间?

基本上我的变量的值是"9/12/2008 12:00:00 AM",我想要"9/12/2008".我使用了一些演员操作员的变种,但没有运气.

CAST(BRSDate AS Date)          ->  Does nothing

CAST(BRSDate AS varchar(11))   ->  2009-05-26 and some dates come out as 0001-01-01
Run Code Online (Sandbox Code Playgroud)

我为重新发帖道歉但不幸的是我发现的解决方案不适合我=(.有人可以帮忙吗?

Hab*_*bib 5

DateTime在.Net包含TimeStamp,您不能真正截断该部分,您可以使用Date将设置时间戳的属性12:00:00 AM,或者您可以通过仅获取日期部分格式化您的日期,然后比较它.

所以为了比较你可以使用:

if (row1date.Date.Equals(row2date.Date))
Run Code Online (Sandbox Code Playgroud)