How to use the startOfMonth function from date-fns

Find comprehensive JavaScript date-fns.startOfMonth code examples handpicked from public code repositorys.

51
52
53
54
55
56
57
58
59
60

db.all('SELECT * FROM statistics', [], (selectErr, rows) => {
	if (!rows) return Logger.warn('No statistics found.');

	const startOfBootWeek = dateFns.startOfWeek(new Date(), { weekStartsOn: 1 }), endOfBootWeek = dateFns.endOfWeek(new Date(), { weekStartsOn: 1 });
	const startOfBootMonth = dateFns.startOfMonth(new Date()), endOfBootMonth = dateFns.endOfMonth(new Date());
	const startOfBootYear = dateFns.startOfYear(new Date()), endOfBootYear = dateFns.endOfYear(new Date());

	const thisWeek = rows.filter(row => dateFns.isWithinInterval(dateFns.parseISO(row.date), { start: startOfBootWeek, end: endOfBootWeek }));
	const thisMonth = rows.filter(row => dateFns.isWithinInterval(dateFns.parseISO(row.date), { start: startOfBootMonth, end: endOfBootMonth }));
fork icon9
star icon40
watch icon0

15
16
17
18
19
20
21
22
23
24
25


function processSelectedDate(selectedDate) {
  const dateSelection = getDateSelection(new Date(), parseISO(selectedDate));
  const fromDate = isValidDateSelection(selectedDate, dateSelection)
    ? parseISO(selectedDate)
    : startOfMonth(new Date());
  const endOfSelectedMonth = endOfMonth(fromDate);
  const toDate = !isFuture(endOfSelectedMonth)
    ? endOfSelectedMonth
    : new Date();
fork icon2
star icon2
watch icon0

160
161
162
163
164
165
166
167
168
169
exports.startOfDayImpl = dateFns.startOfDay
exports.startOfHourImpl = dateFns.startOfHour
exports.startOfISOWeekImpl = dateFns.startOfISOWeek
exports.startOfISOYearImpl = dateFns.startOfISOYear
exports.startOfMinuteImpl = dateFns.startOfMinute
exports.startOfMonthImpl = dateFns.startOfMonth
exports.startOfQuarterImpl = dateFns.startOfQuarter
exports.startOfSecondImpl = dateFns.startOfSecond
exports.startOfTodayImpl = dateFns.startOfToday
exports.startOfTomorrowImpl = dateFns.startOfTomorrow
fork icon0
star icon2
watch icon1

+ 16 other calls in file

90
91
92
93
94
95
96
97
98
99
export function parseDate(dateStr, format, locale = getLocale()) {
  return parseBase(dateStr, format, locale);
}

export function monthStart(date = new Date()) {
  return startOfMonth(date);
}

export function dayStart(date = new Date()) {
  return startOfDay(date);
fork icon6
star icon0
watch icon3

129
130
131
132
133
134
135
136
137
138
    break;
case 'month':
    subIntervalBreaks = dateFns.eachMonthOfInterval(queryInterval);
    if (subIntervalBreaks.length === 0) {
        subIntervalBreaks = [
            dateFns.startOfMonth(queryInterval['start']),
            dateFns.addMilliseconds(dateFns.endOfMonth(queryInterval['end']), 1)
        ];
        break;
    }
fork icon1
star icon0
watch icon0

91
92
93
94
95
96
97
98
99
100
    case "yesterday":
      return startOfYesterday()
    case "week":
      return startOfWeek(val)
    case "month":
      return startOfMonth(val)
  }
  return val
},
isZero(val) {
fork icon0
star icon0
watch icon0

+ 95 other calls in file

411
412
413
414
415
416
417
418
419
420
setup(props, { emit }) {
    const format = vue.computed(() => fp.formatWithOptions({
        locale: props.locale,
        weekStartsOn: props.weekStartsOn,
    }));
    const monthStart = vue.computed(() => dateFns.startOfMonth(props.pageDate));
    const monthEnd = vue.computed(() => dateFns.endOfMonth(props.pageDate));
    const currentMonth = vue.computed(() => ({
        start: monthStart.value,
        end: monthEnd.value,
fork icon0
star icon0
watch icon0

+ 9 other calls in file

465
466
467
468
469
470
471
472
473
474
const today = new Date();
const lastMonth = sub(today, { months: 1 });
const lastWeek = sub(today, { weeks: 1 });
const yesterday = sub(today, { days: 1 });

const thisMonthRange = { start: startOfMonth(today), end: endOfMonth(today) };
const lastMonthRange = { start: startOfMonth(lastMonth), end: endOfMonth(lastMonth) };
const thisWeekRange = { start: startOfWeek(today), end: endOfWeek(today) };
const lastWeekRange = { start: startOfWeek(lastWeek), end: endOfWeek(lastWeek) };
const todayRange = { start: startOfDay(today), end: endOfDay(today) };
fork icon0
star icon0
watch icon0

+ 3 other calls in file

Other functions in date-fns

Sorted by popularity

function icon

date-fns.format is the most popular function in date-fns (3838 examples)