在mysql表中获取日期时间值之间的差异 [英] Get diffrence between datetime values in mysql table

查看:55
本文介绍了在mysql表中获取日期时间值之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



i有mysql表并且有日期时间值,在后面的代码中我想减去这些时间来获得差异。

例如: -

私人TimeSpan get_time_diff(日期时间值1,日期时间价值2)

{

尝试

{



TimeSpan diff0 = value1.Subtract(value2);

返回diff0;

}

catch(例外情况)

{



抛出ex;

}

}



当减去那些值时,最后一个值没有任何值然后给出一个例外,这个位置没有行,那怎么能我解决了这个问题。

dear friends,

i have mysql table and that have date time values,in the code behind i want to subtract these time for get diffrence.
Eg:-
private TimeSpan get_time_diff(DateTime value1, DateTime value2)
{
try
{

TimeSpan diff0 = value1.Subtract(value2);
return diff0;
}
catch (Exception ex)
{

throw ex;
}
}

when subract those value last value doesn't have any value then give an exception there is no row in this position,so how can i solve this problm.

推荐答案

嗨...

看到这个,可能对你来说有用的是你计算的年龄给定日期。

Hi...
see this,may its useful to u.it is calculated age from u are given date.
DateTime pdt = DateTime.Now;
            DateTime dob = DateTime.ParseExact(TextBox8.Text.ToString(), "yyyy-mm-dd", null);
            int age = pdt.Year - dob.Year;
            Label5.Text = age.ToString();



谢谢你。


Thank u.


这篇关于在mysql表中获取日期时间值之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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