2019年1月16日 星期三

C# .Net 日期相減


日期相減

DateTime ST = DateTime.Parse("2018-11-08"); //起始日
DateTime End = DateTime.Parse("2019-02-28"); //結束日
TimeSpan Total = End.Subtract(ST); //日期相減(結束日-起始日)
Response.Write(Total.Days.ToString()); //共幾天
Response.Write(Total.Hours.ToString()); //共幾小時
Response.Write(Total.Minutes.ToString()); //共幾分
Response.Write(Total.TotalDays.ToString()); //總共多少天
Response.Write(Total.TotalHours.ToString()); //總共多少小時
Response.Write(Total.TotalSeconds.ToString()); //總共多少分

沒有留言:

張貼留言

[SQL]各式各樣的GETDATE()時間格式轉換CONVERT

- Microsoft SQL Server T-SQL date and datetime formats -- Date time formats - mssql datetime -- MSSQL getdate returns current system date ...