【问题标题】:To Get Quarterly data with respect to a given Start and end date获取关于给定开始和结束日期的季度数据
【发布时间】:2012-07-09 02:45:20
【问题描述】:

我需要每季度从共享点列表中获取数据,即,我将开始日期和结束日期作为参数传递,取开始日期的月份,必须计算季度。也就是说,我通过 2012 年 2 月 5 日作为我的开始日期然后季度从 2 月 3 月 4 月开始,其余月份也是如此,

现在想象一下,我有 2012 年 12 月、2013 年 1 月和 2 月,其中包括一个季度,在我的情况下,12 月的数据应该包括一个季度,而 1 月和 2 月应该包括另一个季度。, 我该如何解决这个问题。

我必须在我的输出中显示汽车的名称,以及四分之一的汽车总数 我的班级定义是这样的。

public class Foo
{
    public int quantity { get; set; }
    public string cars { get; set; }
    public DateTime date { get; set; }
}

List<Foo> lst = new List<Foo>();
lst.Add(new Foo { date = Convert.ToDateTime("31/Dec/2011"), cars = "cars1", quantity = 20 });
lst.Add(new Foo { date = Convert.ToDateTime("31/Dec/2011"), cars = "cars2", quantity = 30 });
lst.Add(new Foo { date = Convert.ToDateTime("1/Jan/2012"), cars = "cars2", quantity = 80 });
lst.Add(new Foo { date = Convert.ToDateTime("11/Feb/2012"), cars = "cars1", quantity = 10 });
lst.Add(new Foo { date = Convert.ToDateTime("29/Feb/2012"), cars = "cars3", quantity = 7 });
lst.Add(new Foo { date = Convert.ToDateTime("29/May/2012"), cars = "cars3", quantity = 1 });

【问题讨论】:

    标签: c# .net sharepoint-2010


    【解决方案1】:

    “季度”的概念是特定领域的(即业务确定的),因此您需要自己实现。

    class Quarter {
        public static int GetQuarter(Datetime date){
            if (date >= beginningOfQuarter1 && date < endOfQuarter1){
                return 1;
            } else { ... }
        }
    }
    
    // elsewhere
    
    int someDatesQuarter = Quarter.GetQuarter(someDate);
    

    看看我打算用这个去哪里?我敢肯定那里有很多实现,而且可能更面向对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-06
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      相关资源
      最近更新 更多