[TIL] moment.js 활용

김정호·2022년 3월 11일

이번 주의 시작 (월요일) 날짜를 알고 싶을 때

moment.js를 활용,

moment().startOf('isoWeek')

moment 객체를 날짜로 변환

moment().toDate()

이번 달 동안에 생성된 데이터를 가져올 때 (예시)

const monthStart = moment().startOf('month').toDate()
const monthEnd = moment().endOf('month').toDate()

const recordsPerMonth = await WorkOutTime.find({
  userId,
  createdAt: {
    $gte: monthStart,
    $lte: monthEnd,
  },
})
profile
개발자

0개의 댓글