比如说,我有下表:
CREATE TABLE Data (
Id INTEGER PRIMARY KEY,
Value DECIMAL,
Date DATE);
由于应用程序与财务相关,用户可以选择哪一天为本月的第一天。例如,如果他每个月的十分之一得到工资,他可以把这个月的第一天定为第十天。
我想要创建一个查询,它返回用户定义的每月第n天的平均值。例如:
Date | Value
---------------+------
10.01.2016 | 10
11.01.2016 | 15
10.02.2016 | 2
我有一个日历,第一周的第一天开始在星期日,以周六结束。
现在,我只能禁用日历当前月份中的天数,因为我不知道日历中的第一天和最后一天。
我现在使用的代码非常简单:
private List<DateTime> GetDisabledDates(DateTime fromDate, DateTime toDate){
// right now fromDate and toDate are the start and end days in a month
var disabledDates = SearchDates(fromDate, toDate);
return
我需要计算两个日期之间的天数(DateTime),但有一个偏差。我想知道这两天所跨越的月份中每个月有多少天。有没有两个人做这件事的简单方法?
示例:
我有2011年3月30日的开始日期和2011年4月5日的结束日期,那么结果应该类似于:
var result = new Dictionary<DateTime, int>
{
{ new DateTime(2011, 3, 1), 2 },
{ new DateTime(2011, 4, 1), 5 }
};
我试图计算从第一天到昨天的当前月份的天数,而不需要手动更改计数。原始SQL如下所示:
select order_id
from orders
where date > dateadd(-23 to current_date) and date < 'today'
所需的代码如下所示
select order_id
from orders
where date > dateadd(datediff(day,firstdayofthemonth,current_date) to current_date) and date < 'today&