0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

曜日を取得して表示する

Last updated at Posted at 2025-04-09

日付を取得して表示

@echo off
setlocal enabledelayedexpansion

:: ==== 現在の日付を取得 ====
set "TODAY=%DATE%"

:: ==== YYYY MM DD を抽出 ====
for /f "tokens=1-3 delims=/" %%A in ("%TODAY%") do (
    set "YYYY=%%A"
    set "MM=%%B"
    set "DD=%%C"
)

:: ==== DD に付いた (曜日) を除去 ====
for /f "tokens=1 delims=(" %%X in ("!DD!") do set "DD=%%X"

:: ==== 1月 or 2月なら前年として扱う ====
set /a MMINT=10%MM% %% 100
if !MMINT! LSS 3 (
    set /a MMINT+=12
    set /a YYYY-=1
)

:: ==== ツェラーの公式に必要な値 ====
set /a K=!YYYY! %% 100
set /a J=!YYYY! / 100
set /a q=10%DD% %% 100
set /a m=!MMINT!

:: ==== ツェラーの公式 ====
set /a h=(q + (13*(m+1))/5 + K + K/4 + J/4 + 5*J) %% 7

:: ==== 曜日配列(0=土, ..., 6=金) ====
set WEEKDAYS=土 日 月 火 水 木 金

:: ==== 対応する曜日を取得 ====
set i=0
for %%W in (%WEEKDAYS%) do (
    if !i! EQU !h! (
        set "WEEKDAY=%%W"
    )
    set /a i+=1
)

:: ==== 結果表示 ====
echo 今日の曜日は!WEEKDAY!曜日です

endlocal
pause

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?