Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

filter by last week

import moment from 'moment'

export function filterByLaunchDateLastWeek(launches: any) {
  const todayDate = new Date()
  const startDayOfPrevWeek = moment(todayDate).subtract(1, 'week').startOf('week').format('LLLL')
  const lastDayOfPrevWeek = moment(todayDate).subtract(1, 'week').endOf('week').format('LLLL')

  return launches.filter((launch:any) => {
    const launchDate = launch.launch_date_utc
    return moment(launchDate).isBetween(startDayOfPrevWeek, lastDayOfPrevWeek)
  })
}
Source by alisham.hashnode.dev #
 
PREVIOUS NEXT
Tagged: #filter #week
ADD COMMENT
Topic
Name
9+1 =