Datediff getting the date inbetween 2 dates and bind it to a gridview

后端 未结 2 934
情歌与酒
情歌与酒 2020-12-10 01:19

I have a table with \'dateborrowed\' and \'datereturned\' column. What I want to do is I want to get the value in between \'datereturned\' and \'dateborrowed\' and bind it t

2条回答
  •  孤街浪徒
    2020-12-10 02:07

    With C#.NET you can subtract one DateTime from another, resulting in a TimeSpan. For example:

    TimeSpan timespan = (DateTime.Now - new DateTime(2011, 1, 1));
    

    If you want a date in between two dates, you can then add half of this timespan to one of the dates:

    TimeSpan timespan = (DateTime.Now - new DateTime(2011, 1, 1));
    DateTime inBetween = DateTime.Now.AddDays(timespan.TotalDays / 2);
    

提交回复
热议问题