- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想计算给定时间跨度内(一年)的总季度数。
例如:
start date = 1-june -2009
end date = 18-july-2011
count should be = 10.
one more
start date = 4-Jan-2009
end date = 27-oct -2010
count =8.
我没能得到正确的结果。
最佳答案
您的示例是错误的:4-Jan-2009
之间只有 7 个季度和 27-oct -2010
您可以简单地添加对 Microsoft.VisualBasic.dll
的引用到您的项目并使用 DateDiff
:
VB:
Public Shared Function getQuartersBetween(ByVal d1 As Date, ByVal d2 As Date) As Int32
Return DateDiff(DateInterval.Quarter, d1, d2)
End Function
C#:
public static int getQuartersBetween(System.DateTime d1, System.DateTime d2)
{
return Microsoft.VisualBasic.DateAndTime.DateDiff(DateInterval.Quarter, d1, d2);
}
或者您可以编写自己的实现:
public class Quarter
{
public static long GetQuarters(DateTime dt1, DateTime dt2)
{
double d1Quarter = GetQuarter(dt1.Month);
double d2Quarter = GetQuarter(dt2.Month);
double d1 = d2Quarter - d1Quarter;
double d2 = (4 * (dt2.Year - dt1.Year));
return Round(d1 + d2);
}
private static int GetQuarter(int nMonth)
{
if (nMonth <= 3)
return 1;
if (nMonth <= 6)
return 2;
if (nMonth <= 9)
return 3;
return 4;
}
private static long Round(double dVal)
{
if (dVal >= 0)
return (long)Math.Floor(dVal);
return (long)Math.Ceiling(dVal);
}
}
或在 VB.NET 中:
Public Class Quarter
Public Shared Function GetQuarters(ByVal dt1 As DateTime, ByVal dt2 As DateTime) As Long
Dim d1Quarter As Double = GetQuarter(dt1.Month)
Dim d2Quarter As Double = GetQuarter(dt2.Month)
Dim d1 As Double = d2Quarter - d1Quarter
Dim d2 As Double = (4 * (dt2.Year - dt1.Year))
Return Round(d1 + d2)
End Function
Private Shared Function GetQuarter(ByVal nMonth As Integer) As Integer
If nMonth <= 3 Then
Return 1
End If
If nMonth <= 6 Then
Return 2
End If
If nMonth <= 9 Then
Return 3
End If
Return 4
End Function
Private Shared Function Round(ByVal dVal As Double) As Long
If dVal >= 0 Then
Return CLng(Math.Floor(dVal))
End If
Return CLng(Math.Ceiling(dVal))
End Function
End Class
关于c# - 日期之间的季度计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6592580/
我有以下数据框: Data <- data.frame( date = c("2001-01-01", "2001-02-01", "2001-03-01", "2001-04-01", "200
我在基于 [Date] 字段的选择查询中使用这些公式。学期为 1 月至 6 月 1 个学期,7 月至 12 月为 2 个学期。季度是 3 个月的版本(1 月至 3 月等为 1)。 case when
我有一些用户上传的数据,需要根据用户选择的时间段进行存储和排序。期间应该只支持月年或季度年,没有其他,类似于下面: +----+---------+-------+ | id | pe
我有一个 pandas DataFrame,其中有一列(标题)需要被解析为日期时间对象,以便我可以将其转换为时间序列。 Title Gross Domestic Product: Quar
oracle按天,周,月,季度,年查询排序 ? 1
我有 32 年的数据要放入分区表中。但是 BigQuery 说我超过了限制(4000 个分区)。 对于像这样的查询: CREATE TABLE `deleting.day_partition` PAR
我们将从以下数据表开始: id date 1: 1 2016-03-31 2: 1 2015-12-31 3: 1 2015-09-30 4: 1 2015-06-
我知道与计划相关的里程碑的年份和季度(例如“2010”和“4”),并且我想从中选择/创建一个日期时间。有许多巧妙的方法可以用特定日期的格式(“qq”)来识别季度,但不能反过来(或者有吗?)。这是使用
我需要获得给定日期的相应三个月(3 个月的时间段,即 1 月、2 月和 3 月的第一个三个月)。使用 c# System.DateTime 结构我没有设法找到我正在寻找的方法。所以我这样解决了: Da
我的数据集包含 48 周内每一天的信息。[我的数据集截图][1] 我希望创建一个名为“quarter”的新变量,将每一个week变量值=1-12的观测值标记为“a”,意思是“第一季度”;另外,将每个周
我正在寻找一个 java 库,当给出起始日期和截止日期时,它将返回最适用的日期列表(以周、月、季度或年为单位)。我已经手动完成了这项工作,我想知道这是否已经作为标准包的一部分实现和测试。 例子 给定
我想做两件事: 我想将 x 轴格式设置为四分之一。我的时间序列数据以季度为单位。例如,对于日期 2012-12-31 我希望它显示为 2012Q4,对于 2013-03-31 作为 2013Q1 ,对
我是一名优秀的程序员,十分优秀!