Skip to content

Instantly share code, notes, and snippets.

@bnb
Created February 2, 2022 09:21
Show Gist options
  • Save bnb/cfcaeb17d04d5794f592d55ce2c626fd to your computer and use it in GitHub Desktop.
Save bnb/cfcaeb17d04d5794f592d55ce2c626fd to your computer and use it in GitHub Desktop.
const { DateTime } = require('luxon')
const now = DateTime.now()
const currentYear = now.year
const lastMonth = now.minus({ months: 1 })
const lastDayOfPreviousMonth = lastMonth.set({ day: lastMonth.daysInMonth })
const dates = {
now: now.toISODate(), // make `now` usable with ISO date format
lastDayOfPreviousMonth: lastDayOfPreviousMonth.toISODate(), // gets the last day of the previous month
checkFrom: `${currentYear}-${lastDayOfPreviousMonth.month.toString().padStart(2, 0)}-01`, // yyyy-mm-dd
checkUntil: `${currentYear}-${lastDayOfPreviousMonth.month.toString().padStart(2, 0)}-${lastDayOfPreviousMonth.daysInMonth.toString().padStart(2, 0)}` // yyyy-mm-dd-yyyy-mm-dd
}
console.log(currentYear)
module.exports = dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment