asp.net中的datediff函数 [英] datediff function in asp.net

查看:130
本文介绍了asp.net中的datediff函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将start_time和end_time的datediff转换为hours.I已将此差异转换为分钟。这将有效,但我必须将其转换为小时。如何做到这一点?

以下我用来将它转换为分钟的代码。

i have to convert datediff of start_time and end_time into hours.I have convert this diff into minute.this will work, but i have to convert it into hours.how to do this ?
below code that i have used to convert it into minute.

SqlCommand cmd0 = new SqlCommand("select *,Datediff(mi,start_date,end_date) as Duration,Datediff(h,start_date,end_date) from project_log  where (end_date between ''" + txt_datefrom.Text + "'' and ''" + txt_dateto.Text + "'' or start_date between ''" + txt_datefrom.Text + "'' and ''" + txt_dateto.Text + "'') and " + ddlsearchby.SelectedValue + " LIKE ''" + txt_searchText.Text + "%''", cnn);

推荐答案

使用HH在小时数上有所不同。



Use HH to have difference in Hours.

DATEDIFF(HH,start_date, end_date) as Hour


HI,



你可以使用如下:< br $>




you can use like the following:

DateTime a = new DateTime(2008, 01, 02, 06, 30, 00);
DateTime b = new DateTime(2008, 01, 03, 06, 30, 00);
TimeSpan duration = b - a;
double hours = (b-a).TotalHours;



OR




OR

int days = (int)Math.Ceiling(diff.TotalDays);





谢谢



Thanks


这篇关于asp.net中的datediff函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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