Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter by last month

export function filterByLaunchDateLastMonth(launches: any) {
  const todayDate = new Date()
  const startDayOfPrevMonth = moment(todayDate).subtract(1, 'month').startOf('month').format('LLLL')
  const lastDayOfPrevMonth = moment(todayDate).subtract(1, 'month').endOf('month').format('LLLL')

  return launches.filter((launch:any) => {
    const launchDate = launch.launch_date_utc
    return moment(launchDate).isBetween(startDayOfPrevMonth, lastDayOfPrevMonth) 
  })
}
Source by alisham.hashnode.dev #
 
PREVIOUS NEXT
Tagged: #filter #month
ADD COMMENT
Topic
Name
6+4 =