Last active
September 22, 2015 21:24
-
-
Save dieseltravis/36641 to your computer and use it in GitHub Desktop.
Quarterly helper functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private System.DateTime GetLastDayOfMonth(int intMonth, int intYear) | |
| { | |
| //todo: move to utility class | |
| return DateAndTime.DateSerial(intYear, intMonth + 1, 0); | |
| } | |
| // Quarterly helper functions: | |
| public static int GetQuarter(DateTime originalDate) | |
| { | |
| return ((originalDate.Month - 1) / 3) + 1; | |
| } | |
| public static DateTime AddQuarters(DateTime originalDate, int quarters) | |
| { | |
| return originalDate.AddMonths(quarters * 3); | |
| } | |
| public static DateTime GetFirstDayOfQuarter(DateTime originalDate) | |
| { | |
| return AddQuarters(new DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate) - 1); | |
| } | |
| public static DateTime GetLastDayOfQuarter(DateTime originalDate) | |
| { | |
| return AddQuarters(new DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate)).AddDays(-1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // quarterly date helpers | |
| var getQuarter = function (originalDate) { | |
| var newDate = new Date(originalDate.getTime()); | |
| var quarter = Math.floor(((newDate.getMonth()) / 3) + 1); | |
| return quarter; | |
| }, | |
| addQuarters = function (originalDate, quarters) { | |
| var newDate = new Date(originalDate.getTime()); | |
| newDate.setMonth(newDate.getMonth() + (quarters * 3)); | |
| return newDate; | |
| }, | |
| getFirstDayOfQuarter = function (originalDate) { | |
| var newDate = new Date(originalDate.getTime()); | |
| var firstDay = addQuarters(new Date(newDate.getFullYear(), 0, 1), getQuarter(newDate) - 1); | |
| return firstDay; | |
| }, | |
| getLastDayOfQuarter = function (originalDate) { | |
| var newDate = new Date(originalDate.getTime()); | |
| var lastDay = addQuarters(getFirstDayOfQuarter(newDate), 1); | |
| lastDay.setDate(lastDay.getDate() - 1); | |
| return lastDay; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Private Function GetLastDayOfMonth(ByVal intMonth As Integer, ByVal intYear As Integer) As Date | |
| 'todo: move to utility class | |
| GetLastDayOfMonth = DateSerial(intYear, intMonth + 1, 0) | |
| End Function | |
| ' Quarterly helper functions: | |
| Public Shared Function GetQuarter(ByVal originalDate As DateTime) As Integer | |
| Return ((originalDate.Month - 1) \ 3) + 1 | |
| End Function | |
| Public Shared Function AddQuarters(ByVal originalDate As DateTime, ByVal quarters As Integer) As DateTime | |
| Return originalDate.AddMonths(quarters * 3) | |
| End Function | |
| Public Shared Function GetFirstDayOfQuarter(ByVal originalDate As DateTime) As DateTime | |
| Return AddQuarters(New DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate) - 1) | |
| End Function | |
| Public Shared Function GetLastDayOfQuarter(ByVal originalDate As DateTime) As DateTime | |
| Return AddQuarters(New DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate)).AddDays(-1) | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment