C# 计算时间间隔

 var dt = DateTime.Now;
            TimeSpan ts1 = new TimeSpan(dt.Ticks);
            TimeSpan ts2 = new TimeSpan(dt.AddDays(-1).Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();
            Console.WriteLine(ts.TotalSeconds);


当月第一天0时0分0秒:


DateTime.Now.AddDays(1 - DateTime.Now.Day).Date


当月最后一天23时59分59秒:


DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1)

--最大支付时间

select * from CMCustomer A inner join
(select MAX(AddTime) as addtime,CustomerID from CMChargeGoodsOrderDetail where Status=2 group by CustomerID) tab on tab.CustomerID=A.uid
where 1=1

 
原文地址:https://www.cnblogs.com/chenwolong/p/14360891.html