如何在计算的日子里删除小时的小时数...... asp.net,C# [英] How to remove hours minuts seconds in caliculated days ...asp.net, C#

查看:88
本文介绍了如何在计算的日子里删除小时的小时数...... asp.net,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过后面的代码创建一个Gridview表,

在Gridview表中,一列是从两个日期之间计算的天数,

对于列格式我在RowDataBound编写代码,

所以Days列格式没有转换,

显示Days.HH MM SS FFF也



请愿。任何人帮助我..



我尝试过:



  protected   void  Page_Load(对象发​​件人,EventArgs e)
{
// Gridview数据绑定
DataClassesDataContext db = new DataClassesDataContext();
var sumo = 来自 i db.Chech_ins
let Dys = DateTime.Now - i.IN_Date
select new
{Gues_Name = i.Room_num,
IN_Date = i.IN_Date,
Today_Date = DateTime.Now,
天= Dys,
总计= i.Tariff * 2
};
GridView1.DataSource = sumo;
GridView1.DataBind();

}



受保护 void GridView1_RowDataBound( object sender,GridViewRowEventArgs e)
{

// 用于更改列格式
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells [ 1 ]。Text = Convert.ToDateTime(e。 Row.Cells [ 1 ]。文本).ToString( DD-MM-YYYY);
e.Row.Cells [ 2 ]。Text = Convert.ToDateTime(e.Row.Cells [ 2 ]。文本).ToString( dd-MM-yyyy);
e.Row.Cells [ 3 ]。Text = double .Parse(e.Row .Cells [ 3 ]。Text).ToString();
e.Row.Cells [ 4 ]。Text = Convert.ToInt32(e.Row.Cells [ 4 ]文本)的ToString();
}
}

解决方案

尝试

 Dys = DateDiff(DateInterval.Day,DateTime 。现在,i.IN_Date)

而不是

 Dys = DateTime.Now  -  i.IN_Date 


Based在你的帖子描述中,看起来代码是针对List / Enumerable对象而不是LINQ to Entities的查询,因为它应该抛出错误。无论如何,请尝试以下。



  Dys = DateTime.Now。减去(i.IN_Date).Days 





如果最终更改代码以编写LINQ to Entities查询,则使用下面的代码。

  Dys = DbFunctions.DiffDays(i.IN_Date,DateTime.Now)


I am was create one Gridview table through code behind,
In the Gridview table one column is for days counting from between two dates,
For the columns formate i wrote code in RowDataBound,
so in that Days column format is not converting,
It was showing Days.HH MM SS FFF also

pls. any one help me ..

What I have tried:

protected void Page_Load(object sender, EventArgs e)
    {
       // Gridview Data binding 
        DataClassesDataContext db = new DataClassesDataContext();
          var sumo = from i in db.Chech_ins
                     let Dys = DateTime.Now - i.IN_Date
                     select new
                   {   Gues_Name = i.Room_num,
                       IN_Date= i.IN_Date, 
                       Today_Date=DateTime.Now,
                       Days = Dys,
                       Total = i.Tariff * 2,
                   };
        GridView1.DataSource = sumo;
        GridView1.DataBind();
    
    }



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

       // for change the column formate
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
    
            e.Row.Cells[1].Text = Convert.ToDateTime(e.Row.Cells[1].Text).ToString("dd-MM-yyyy");
            e.Row.Cells[2].Text = Convert.ToDateTime(e.Row.Cells[2].Text).ToString("dd-MM-yyyy");
            e.Row.Cells[3].Text = double.Parse(e.Row.Cells[3].Text).ToString();
            e.Row.Cells[4].Text = Convert.ToInt32(e.Row.Cells[4].Text).ToString();
        }
    }

解决方案

try

Dys = DateDiff(DateInterval.Day, DateTime.Now, i.IN_Date)

instead of

Dys = DateTime.Now - i.IN_Date


Based on your post description, look like the code is query against a List / Enumerable object and not LINQ to Entities because it should had thrown an error. Anyway, try below.

let Dys = DateTime.Now.Subtract(i.IN_Date).Days



If you end up changing the code to write LINQ to Entities query, then use the below code.

let Dys = DbFunctions.DiffDays(i.IN_Date, DateTime.Now)


这篇关于如何在计算的日子里删除小时的小时数...... asp.net,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆