计算起始日期和结束日期为这个季度和去年季度 [英] Calculate StartDate and EndDate for This Quarter and Last Quarter

查看:303
本文介绍了计算起始日期和结束日期为这个季度和去年季度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算起始日期和当前季度的结束日期,并在vb.net的previous区。

I need to calculate a StartDate and EndDate of a current Quarter and the previous Quarter in vb.net.

推荐答案

原谅我缺乏一个VB.net具体的答案,但由于一个通用的排序,在一些伪语言的各种功能日期的对象(与基于零日和月索引)...

Forgive my lack of a VB.net-specific answer, but given a generic sort of date object with various functions in some pseudo-language (with zero-based day and month indexes)...

//round the current month number down to a multiple of 3
ThisQuarterStart = DateFromYearMonthDay(Today.Year,Today.Month-(Today.Month%3),0);
//round the current month number up to a multiple of 3, then subtract 1 day
ThisQuarterEnd = DateFromYearMonthDay((Today.Month<9)?(Today.Year):(Today.Year+1),(Today.Month-(Today.Month%3)+3)%12,0) - 1;
//same as above, but minus 3 months
LastQuarterStart = DateFromYearMonthDay((Today.Month<3)?(Today.Year-1):(Today.Year),(Today.Month-(Today.Month%3)+9)%12,0)
LastQuarterEnd = ThisQuarterStart - 1;

修改转换上面的伪code到工作VB.Net: /斯特凡

Dim ThisQuarterStart As Date = New Date(Today.Year, Today.Month - (Today.Month Mod 3) + 1, 1)  
Dim ThisQuarterEnd As Date = New Date(CInt(IIf(Today.Month < 9, Today.Year, Today.Year + 1)), (Today.Month - (Today.Month Mod 3) + 3 Mod 12) + 1, 1).AddDays(-1)
Dim LastQuarterStart As Date = New Date(CInt(IIf(Today.Month < 3, Today.Year - 1, Today.Year)), (Today.Month - (Today.Month Mod 3) + 9 Mod 12) + 1, 1)
Dim LastQuarterEnd As Date = ThisQuarterStart.AddDays(-1)

这篇关于计算起始日期和结束日期为这个季度和去年季度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆