Skip to content

Instantly share code, notes, and snippets.

@r-k-b
Last active October 19, 2016 04:44
Show Gist options
  • Save r-k-b/db1eb0e00364cb592e1d8674bb03cb5c to your computer and use it in GitHub Desktop.
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)
// 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