Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created April 25, 2016 04:13
Show Gist options
  • Save hirokazumiyaji/9ce49088d9bc12b42134e77ab84ead94 to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/9ce49088d9bc12b42134e77ab84ead94 to your computer and use it in GitHub Desktop.
最終ログインが 30 分以内か
<?php
$user = array(
'id' => 1,
'last_logged_in_at' => date('Y-m-d H:i:s', strtotime('-20 minute'))
);
$now = new DateTimeImmutable();
$latLoggedInAt = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $user['last_logged_in_at']);
if ($now.diff($lastLoggedInAt) <= 30) {
echo '30 分以内。' . "¥n";
} else {
echo '30 分以内ではない。' . "¥n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment