생활

날짜 더하기·빼기 계산기

기준일에서 일·주·개월·년을 더하거나 빼고, 주말 제외 영업일 계산도 지원합니다.

입력값은 브라우저에서만 계산되며 서버로 전송되지 않습니다.

공휴일은 반영하지 않고 토·일요일만 제외합니다.

계산 결과

—

—

  • 기준일—
  • 계산+ 1일
  • 날짜 차이—
  • 결과일—

월·연 단위는 말일을 넘지 않도록 보정합니다. 예: 1월 31일 + 1개월 = 2월 말일. 영업일 계산은 토·일요일만 제외하며 법정·임시공휴일은 포함합니다.

최근 입력0/8

입력이 3초간 멈추면 이 브라우저에 자동 저장됩니다.

입력이 3초간 멈추면 이 브라우저에만 저장됩니다. 항목을 클릭하면 그때의 입력값으로 복원됩니다.

이 도구는 이렇게 계산합니다

결과를 믿기 전에 계산 원리와 가정을 확인하세요.

  1. 일·주 단위는 달력 날짜로 더하거나 빼고, 월·연 단위는 말일을 넘지 않도록 보정합니다.
  2. 영업일 옵션은 토·일요일만 제외하며 법정·임시공휴일은 반영하지 않습니다.
  3. 결과일의 요일과 기준일로부터의 날짜 차이를 함께 표시합니다.

자주 묻는 질문

1월 31일에서 1개월을 더하면 어떻게 되나요?

말일을 넘지 않도록 보정해 2월 말일로 계산합니다. 예를 들어 2026년 1월 31일 + 1개월은 2026년 2월 28일입니다.

영업일 계산에 공휴일도 반영되나요?

아니요. 영업일 옵션은 토요일과 일요일만 제외합니다. 법정공휴일·임시공휴일·회사 휴무일은 별도로 확인해야 합니다.

날짜 차이 계산기와 무엇이 다른가요?

기존 날짜 계산기는 두 날짜의 차이와 D-day를 계산합니다. 이 계산기는 기준일에서 일정 기간을 더하거나 빼서 결과 날짜를 구합니다.

제작 코드

이 페이지에서 실제로 사용하는 Vue 3 컴포넌트입니다. 계산식과 화면 구성을 그대로 확인하고 복사할 수 있습니다.

도구 전체 코드 보기
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { diffDays, parseDate, todayISO } from '~/utils/calc'
import CalculatorHistory from '~/components/calculators/CalculatorHistory.vue'

type Unit = 'days' | 'weeks' | 'months' | 'years'
type Direction = 'add' | 'subtract'

const baseDate = ref('')
const amount = ref(1)
const unit = ref<Unit>('days')
const direction = ref<Direction>('add')
const businessDays = ref(false)

function toISO(date: Date) {
  return date.toISOString().slice(0, 10)
}

function addMonths(date: Date, months: number) {
  const target = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + months, 1))
  const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate()
  target.setUTCDate(Math.min(date.getUTCDate(), lastDay))
  return target
}

function addBusinessDays(date: Date, count: number) {
  const target = new Date(date)
  const step = count >= 0 ? 1 : -1
  let remaining = Math.abs(count)
  while (remaining > 0) {
    target.setUTCDate(target.getUTCDate() + step)
    const weekday = target.getUTCDay()
    if (weekday !== 0 && weekday !== 6) remaining -= 1
  }
  return target
}

onMounted(() => {
  baseDate.value = todayISO()
})

const base = computed(() => parseDate(baseDate.value))
const count = computed(() => Math.max(0, Math.floor(Number(amount.value) || 0)))
const signed = computed(() => (direction.value === 'add' ? 1 : -1))

const target = computed(() => {
  if (!base.value) return null
  if (unit.value === 'days' && businessDays.value) return addBusinessDays(base.value, signed.value * count.value)
  if (unit.value === 'weeks') {
    const targetDate = new Date(base.value)
    targetDate.setUTCDate(targetDate.getUTCDate() + signed.value * count.value * 7)
    return targetDate
  }
  if (unit.value === 'months') return addMonths(base.value, signed.value * count.value)
  if (unit.value === 'years') return addMonths(base.value, signed.value * count.value * 12)
  const targetDate = new Date(base.value)
  targetDate.setUTCDate(targetDate.getUTCDate() + signed.value * count.value)
  return targetDate
})

const targetISO = computed(() => (target.value ? toISO(target.value) : ''))
const targetLabel = computed(() => {
  if (!target.value) return '—'
  return new Intl.DateTimeFormat('ko-KR', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'long',
    timeZone: 'UTC',
  }).format(target.value)
})
const dayDiff = computed(() => (base.value && target.value ? diffDays(base.value, target.value) : null))

const unitLabel: Record<Unit, string> = {
  days: '일',
  weeks: '주',
  months: '개월',
  years: '년',
}

const historySnapshot = computed(() => ({
  baseDate: baseDate.value,
  amount: amount.value,
  unit: unit.value,
  direction: direction.value,
  businessDays: businessDays.value,
}))
const historyLabel = computed(() => `${baseDate.value || '—'} ${direction.value === 'add' ? '+' : '−'} ${fmt(amount.value)}${unitLabel[unit.value]}`)
function restoreHistory(data: Record<string, unknown>) {
  baseDate.value = String(data.baseDate ?? '')
  amount.value = Number(data.amount) || 0
  unit.value = (['days', 'weeks', 'months', 'years'].includes(String(data.unit)) ? data.unit : 'days') as Unit
  direction.value = data.direction === 'subtract' ? 'subtract' : 'add'
  businessDays.value = data.businessDays === true
}
</script>

<template>
  <div class="calc-card">
    <div class="calc-tabs" role="tablist" aria-label="더하기 또는 빼기">
      <button type="button" class="calc-tab" :class="{ active: direction === 'add' }" @click="direction = 'add'">더하기</button>
      <button type="button" class="calc-tab" :class="{ active: direction === 'subtract' }" @click="direction = 'subtract'">빼기</button>
    </div>

    <div class="calc-grid">
      <div class="calc-form">
        <div class="calc-field">
          <label for="date-add-base">기준일</label>
          <input id="date-add-base" v-model="baseDate" class="calc-input" type="date" />
        </div>

        <div class="calc-field">
          <label for="date-add-amount">더하거나 뺄 기간</label>
          <div class="calc-inline">
            <input
              id="date-add-amount"
              v-model.number="amount"
              class="calc-input"
              type="number"
              min="0"
              step="1"
              inputmode="numeric"
            />
            <select v-model="unit" class="calc-select" aria-label="기간 단위">
              <option value="days">일</option>
              <option value="weeks">주</option>
              <option value="months">개월</option>
              <option value="years">년</option>
            </select>
          </div>
        </div>

        <div v-if="unit === 'days'" class="calc-field">
          <label for="date-add-business">
            <input id="date-add-business" v-model="businessDays" type="checkbox" />
            주말 제외 영업일로 계산
          </label>
          <p class="calc-hint">공휴일은 반영하지 않고 토·일요일만 제외합니다.</p>
        </div>
      </div>

      <div class="calc-result" aria-live="polite">
        <p class="calc-result-label">계산 결과</p>
        <p class="calc-result-hero">{{ targetISO || '—' }}</p>
        <p class="calc-result-sub">{{ targetLabel }}</p>
        <ul class="calc-result-list">
          <li class="calc-result-row"><span>기준일</span><strong>{{ baseDate || '—' }}</strong></li>
          <li class="calc-result-row"><span>계산</span><strong>{{ direction === 'add' ? '+' : '−' }} {{ fmt(amount) }}{{ unitLabel[unit] }}</strong></li>
          <li class="calc-result-row"><span>날짜 차이</span><strong>{{ dayDiff === null ? '—' : `${fmt(dayDiff)}일` }}</strong></li>
          <li class="calc-result-row total"><span>결과일</span><strong>{{ targetISO || '—' }}</strong></li>
        </ul>
        <p v-if="businessDays && unit === 'days'" class="calc-warning">
          주말만 제외한 영업일 기준입니다. 공휴일·임시공휴일은 반영하지 않았습니다.
        </p>
      </div>
    </div>

    <p class="calc-note">
      월·연 단위는 말일을 넘지 않도록 보정합니다. 예: 1월 31일 + 1개월 = 2월 말일.
      영업일 계산은 토·일요일만 제외하며 법정·임시공휴일은 포함합니다.
    </p>
  </div>

  <CalculatorHistory tool="date-add" :snapshot="historySnapshot" :label="historyLabel" @restore="restoreHistory" />
</template>
공통 입력 기록 컴포넌트 보기
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'

interface HistoryEntry {
  id: string
  at: number
  label: string
  data: Record<string, unknown>
}

const props = defineProps<{
  tool: string
  snapshot: Record<string, unknown>
  label: string
}>()

const emit = defineEmits<{ restore: [data: Record<string, unknown>] }>()

const MAX_ENTRIES = 8
const SAVE_DELAY = 3000

const entries = ref<HistoryEntry[]>([])
const ready = ref(false)
const restoredId = ref('')
const storageKey = computed(() => `euninfo.calc-history.v1:${props.tool}`)
let saveTimer: ReturnType<typeof setTimeout> | undefined
let initialTimer: ReturnType<typeof setTimeout> | undefined
let initialSnapshot = ''

onMounted(() => {
  load()
  ready.value = true
  // 부모의 onMounted 기본값 주입(날짜 등) 뒤에 초기 상태를 캡처한다.
  initialTimer = setTimeout(() => {
    initialSnapshot = JSON.stringify(props.snapshot)
  }, 0)
})

onBeforeUnmount(() => {
  if (saveTimer) clearTimeout(saveTimer)
  if (initialTimer) clearTimeout(initialTimer)
})

watch(
  () => props.snapshot,
  () => {
    if (!ready.value) return
    if (saveTimer) clearTimeout(saveTimer)
    saveTimer = setTimeout(save, SAVE_DELAY)
  },
  { deep: true },
)

function load() {
  try {
    const raw = localStorage.getItem(storageKey.value)
    if (!raw) return
    const parsed: unknown = JSON.parse(raw)
    if (!Array.isArray(parsed)) return
    entries.value = parsed
      .filter((item): item is HistoryEntry => {
        if (!item || typeof item !== 'object') return false
        const entry = item as Partial<HistoryEntry>
        return typeof entry.id === 'string' && typeof entry.at === 'number' && typeof entry.label === 'string' && !!entry.data && typeof entry.data === 'object'
      })
      .slice(0, MAX_ENTRIES)
  } catch {
    entries.value = []
  }
}

function persist() {
  try {
    localStorage.setItem(storageKey.value, JSON.stringify(entries.value))
  } catch {
    // 저장 공간이 없거나 브라우저가 막은 경우 조용히 무시한다.
  }
}

function save() {
  const data = JSON.parse(JSON.stringify(props.snapshot)) as Record<string, unknown>
  const json = JSON.stringify(data)
  if (!entries.value.length && json === initialSnapshot) return

  const now = Date.now()
  const label = props.label.trim() || '최근 입력'
  const existing = entries.value.find((entry) => JSON.stringify(entry.data) === json)

  if (existing) {
    existing.at = now
    existing.label = label
    entries.value = [existing, ...entries.value.filter((entry) => entry.id !== existing.id)]
  } else {
    entries.value = [
      {
        id: `${now}-${Math.random().toString(36).slice(2, 8)}`,
        at: now,
        label,
        data,
      },
      ...entries.value,
    ].slice(0, MAX_ENTRIES)
  }
  persist()
}

function restore(entry: HistoryEntry) {
  emit('restore', JSON.parse(JSON.stringify(entry.data)) as Record<string, unknown>)
  restoredId.value = entry.id
  setTimeout(() => {
    if (restoredId.value === entry.id) restoredId.value = ''
  }, 1500)
}

function remove(id: string) {
  entries.value = entries.value.filter((entry) => entry.id !== id)
  persist()
}

function clear() {
  entries.value = []
  try {
    localStorage.removeItem(storageKey.value)
  } catch {
    // ignore
  }
}

function formatTime(at: number) {
  return new Intl.DateTimeFormat('ko-KR', {
    month: 'numeric',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
  }).format(new Date(at))
}
</script>

<template>
  <section class="calc-history" aria-label="최근 입력 기록">
    <div class="calc-history-head">
      <strong>최근 입력</strong>
      <span class="calc-history-count">{{ entries.length }}/{{ MAX_ENTRIES }}</span>
      <button v-if="entries.length" type="button" class="calc-history-clear" @click="clear">전체 삭제</button>
    </div>

    <p v-if="!entries.length" class="calc-history-empty">
      입력이 3초간 멈추면 이 브라우저에 자동 저장됩니다.
    </p>
    <ul v-else class="calc-history-list">
      <li v-for="entry in entries" :key="entry.id" class="calc-history-row" :class="{ restored: restoredId === entry.id }">
        <button type="button" class="calc-history-load" :aria-label="`${entry.label} 입력값 불러오기`" @click="restore(entry)">
          <span class="calc-history-label">{{ entry.label }}</span>
          <time class="calc-history-time">{{ formatTime(entry.at) }}</time>
        </button>
        <button type="button" class="calc-history-remove" :aria-label="`${entry.label} 기록 삭제`" @click="remove(entry.id)">×</button>
      </li>
    </ul>

    <p class="calc-history-note">
      입력이 3초간 멈추면 이 브라우저에만 저장됩니다. 항목을 클릭하면 그때의 입력값으로 복원됩니다.
    </p>
  </section>
</template>

함께 쓰면 좋은 도구

이런 계산기가 필요하세요?

우리 업무에 맞는 계산기·관리 도구를 함께 만들 수 있습니다.

의뢰 등록하기