Last active
October 19, 2016 04:44
-
-
Save r-k-b/db1eb0e00364cb592e1d8674bb03cb5c to your computer and use it in GitHub Desktop.
Get a list of the start and end dates of the current and the previous month, as ISO 8601 formatted dates. (Power Query)
This file contains 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
// Get a list of the start and end dates of the relative month, as ISO 8601 formatted dates. | |
// | |
// E.g.: | |
// ``` | |
// { | |
// "2016-09-01", | |
// "2016-09-31" | |
// } | |
// ``` | |
// | |
// Source: <https://gist.github.com/r-k-b/db1eb0e00364cb592e1d8674bb03cb5c> | |
let | |
GetMonthDates = (monthOffset as number) as list => let | |
now = DateTime.LocalNow(), | |
otherMonth = Date.AddMonths(now, monthOffset), | |
month1Start = Date.StartOfMonth(otherMonth), | |
month1End = Date.AddDays(Date.EndOfMonth(otherMonth), -1), | |
dates = { | |
month1Start, | |
month1End | |
}, | |
result = List.Transform( | |
dates, | |
each DateTime.ToText(_, "yyyy-MM-dd") | |
) | |
in | |
result | |
in | |
GetMonthDates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment