DateDifference[date1,date2]
date1から date2までの日数を返す.
DateDifference[date1,date2,"unit"]
date1と date2の違いを指定した単位で返す.
DateDifference[date1,date2,{"unit1","unit2",…}]
違いを連続する"uniti"に対応する要素のリストとして返す.
DateDifference
DateDifference[date1,date2]
date1から date2までの日数を返す.
DateDifference[date1,date2,"unit"]
date1と date2の違いを指定した単位で返す.
DateDifference[date1,date2,{"unit1","unit2",…}]
違いを連続する"uniti"に対応する要素のリストとして返す.
詳細とオプション
- DateDifferenceは,指定された日付間の時間量を計算し,結果を物理的な期間か暦ステップの数として表す.
- DateDifferenceはQuantityオブジェクトを返す.
- 日付は次の形式で指定できる.
-
DateObject[…] 日付オブジェクト {y,m,d} 年,月,日 {y,m} 指定の月の最初の日 {y} y 年1月1日 "string" 文字列としての日付("Jan. 1, 2022") {y,m,d,h,m,s} 正確な時間 time 絶対時間指定 - 使用可能な単位は,"Year","Quarter","Month","Week","Day","Hour","Minute","Second"である.
- {y,m,d}は{y,m,d,0,0,0}等と等しいとみなされる.
- DateDifferenceは次のオプションを取る.
-
DayCountConvention "ActualActual" 差を計算するときに使われる数え方の慣例 Method Automatic 使用する日付計算法 - 日付計算は,変数の期間(例:"Month")として加えられた時間ステップを物理的な期間に変換する(連続計算)か,すべてを離散的な暦のステップとして扱う(離散計算)かする.
- オプション値Method"Continuous"は連続計算を実装する.離散計算はMethodrolling で実装される.指標可能なオプションには"RollForward","RollBackward","RollOver"がある.デフォルトは"RollBackward"である.
- 離散計算では,例えば1ヶ月を加えると存在しない日付(例:February 30)になることがある.そのような場合に日付を解決するために使えるオプションには以下の3つある.
-

"RollBackward" 既存の最後の日付(Feb 28)まで戻る 
"RollForward" 次の既存の日付(Mar 1)まで進む 
"RollOver" 次の既存の日付(Mar …)から増分する - 日数で数えられたDateDifferenceは,差の大きさには関係なく,日数を数える慣例に従う.
- DateDifference[date2]は,現行の日付から date2までの日数を分数で返す.
例題
すべて開く すべて閉じる例 (4)
DateDifference[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 7, 4}, "Day"]]DateDifference[{2022, 8, 29}, {2023, 1, 1}]DateDifference[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 7, 4}, "Day"], "Week"]DateDifference[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 7, 4}, "Day"], {"Day", "Hour", "Minute"}]スコープ (8)
DateDifference[DateObject[{2022, 7, 4}, "Day"], DateObject[{2022, 1, 1}, "Day"]]もし一つの日付しか与えられていない場合は,現在の日付との差が返される:
DateDifference[Yesterday]日付形式 (3)
DateStringがサポートしている任意の形式で日付を返す:
DateDifference["May 9, 2021", "Nov 4, 2021"]DateDifference["May 9, 2021", DateObject[{2021, 11, 4}, "Day"]]DateDifferenceは{y,m,d,h,m,s}形式の時間を使うことができる:
DateDifference[{2022, 1, 1, 5, 16, 17}, {2022, 1, 5, 7, 8, 11}]単位 (3)
DateDifference[DateObject[{2022, 1, 1}, "Day"], DateObject[{2022, 6, 1}, "Day"], "Hour"]DateDifference[DateObject[{1936, 8, 14}, "Day"], DateObject[{2000, 12, 1}, "Day"], "Year"]DateDifference[DateObject[{2023, 8, 14}, "Day"], DateObject[{2024, 12, 1}, "Day"], {"Month", "Day"}]オプション (6)
DayCountConvention (2)
日数を数える慣例は,月の最終日に適用される数え方について異なる:
Table[DateDifference[DateObject[{2022, 1, 31}, "Day"], DateObject[{2023, 1, 31}, "Day"], DayCountConvention -> i] + DateDifference[DateObject[{2023, 1, 31}, "Day"], DateObject[{2023, 2, 28}, "Day"], DayCountConvention -> i], {i, {"ThirtyEPlus360", "Thirty360", "Thirty360US"}}]DateDifference[DateObject[{2022, 1, 31}, "Day"], DateObject[{2023, 3, 31}, "Day"], "Year", DayCountConvention -> "Thirty360"]CalendarType (2)
Method (2)
DateDifference[DateObject[{2022, 3, 31}, "Day"], DateObject[{2022, 6, 30}, "Day"], {"Month", "Day"}]Method"RollForward"を使うと日付間の距離は2ヶ月と30日になる:
DateDifference[DateObject[{2022, 3, 31}, "Day"], DateObject[{2022, 6, 30}, "Day"], {"Month", "Day"}, Method -> "RollForward"]DateDifference[DateObject[{2020, 1, 30}], DateObject[{2023, 3, 1}], {"Month", "Day"}, Method -> #]& /@ {"Continuous", "RollForward", "RollBackward", "RollOver"}アプリケーション (2)
DateDifference[DateObject[{2000}, "Year", "Gregorian", -6.], DateObject[], {"Month", "Day", "Year"}]DateDifference[{2022, 3, 21}, {2022, 9, 21}]閏年でなければ,9月21日から3月21日までは181日である:
DateDifference[{2022, 9, 21}, {2023, 3, 21}]LeapYearQ[{2022, 3, 21}]DateDifference[{2023, 9, 21}, {2024, 3, 21}]LeapYearQ[{2020, 3, 21}]特性と関係 (1)
DatePlusは時間単位を日付に加えるのに対し,DateDifferenceは日付間の単位を計算する:
DateDifference[DateObject[{2022, 1}, "Month"], DateObject[{2022, 3}, "Month"], "Month"]DatePlus[DateObject[{2022, 1}, "Month"], %]DatePlus[DateObject[{2022, 1}, "Month"], {2, "Month"}]DateDifference[DateObject[{2022, 1}, "Month"], %, "Month"]考えられる問題 (2)
DateDifference["2/4/99", "Feb. 23, 1999"]DateObjectを使って異なる解釈間の曖昧さを回避する:
DateDifference[DateObject[{"2/4/99", {"Day", "Month", "YearShort"}}], "Feb. 23, 1999"]以前のWolfram言語のリリースでは,DateDifferenceは純粋な数値結果を返した.このレガシー動作はSetSystemOptionsで有効にすることができる:
DateDifference[Yesterday, Tomorrow]SetSystemOptions["DataOptions" -> "ReturnQuantities" -> False];DateDifference[Yesterday, Tomorrow]Quantity結果は上記と同じシステムオプションの値をTrueに設定することで,再び有効にすることができる:
SetSystemOptions["DataOptions" -> "ReturnQuantities" -> True];DateDifference[Yesterday, Tomorrow]関連するガイド
-
▪
- 日付と時刻 ▪
- 金融計算 ▪
- 距離と類似度の測定基準
テキスト
Wolfram Research (2007), DateDifference, Wolfram言語関数, https://reference.wolfram.com/language/ref/DateDifference.html (2022年に更新).
CMS
Wolfram Language. 2007. "DateDifference." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/DateDifference.html.
APA
Wolfram Language. (2007). DateDifference. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DateDifference.html
BibTeX
@misc{reference.wolfram_2026_datedifference, author="Wolfram Research", title="{DateDifference}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/DateDifference.html}", note=[Accessed: 15-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_datedifference, organization={Wolfram Research}, title={DateDifference}, year={2022}, url={https://reference.wolfram.com/language/ref/DateDifference.html}, note=[Accessed: 15-October-2026]}