Skip to main content

日付同士の引き算

Python

py
d2 - d1   # timedelta
py
t2 - t1   # timedelta
d2 - d1 # timedelta

delta.seconds
delta.days

PHP

php
$diff = $d2->diff($d1);
php
$diff = $d2->diff($d1);

$diff->y
$diff->m
$diff->d

$diff->format('%Y-%M-%D %H:%I:%S'); // DateTime::format と書式が違う・・?
$diff->format("%a"); // total days
(new DateTime($diff->format('%Y-%M-%D %H:%I:%S')))->getTimestamp(); // total timestamp

Ruby

rb
d2 - d1   # Rational (28/1) のような値が返ってくる
rb
t2 - t1   # seconds
d2 - d1 # Rational (28/1) のような値が返ってくる