ユーザ用ツール

サイト用ツール


サイドバー

Index

はじめてのおつかい






DokuWiki整形記法


PlayGround



development:language:php:tips:getdate

文書の過去の版を表示しています。


日付の取得

<?php
// 本日の日付
echo date("Y/m/d");
// 今月末日
echo date("Y/m/t");
// 1日前
echo date("Y/m/d",strtotime("-1 day"));
// 1週間前
echo date("Y/m/d",strtotime("-1 week"));
// 1ヶ月前
echo date("Y/m/d",strtotime("-1 month"));
// 来月末日
echo date("Y/m/t",strtotime("1 month"));
// 1年前
echo date("Y/m/d",strtotime("-1 year"));
// 1日後
echo date("Y/m/d",strtotime("+1 day"));
// 3日前
echo date("Y/m/d",strtotime("-3 day"));
// 次の日曜日
echo date("Y/m/d",strtotime("next Sunday"));
// 次の次の日曜日
echo date("Y/m/d",strtotime("+2 Sunday"));
// この前の日曜日
echo date("Y/m/d",strtotime("last Sunday"));
// 先週の日曜日
echo date("Y/m/d",strtotime("2 weeks ago Sunday"));
// 先週の土曜日
echo date("Y/m/d",strtotime("last Saturday"));
//来月1日
echo date("Y/m/d",strtotime("first day of next month"));

※「この前の日曜日」と「先週の日曜日」は違うので注意

  • echo date(“Y/m/d”);
    • 2024/05/04
  • echo date(“Y/m/d H:i”);
    • 2024/05/04 02:33
  • echo date(“Y/m/d H:i”, strtotime(“2010/9/8 6:05”));
    • 2010/09/08 06:05
  • echo date(“Y/m/d H:i”, strtotime(“+23 hours”,strtotime(“2010/9/8 6:05”)));
    • 2010/09/09 05:05
  • echo date(“Y/m/d H:i”, strtotime(“-9 hours”,strtotime(“2010/9/8 6:05”)));
    • 2010/09/07 21:05
  • echo date(“YmdHmi”);
    • 20240504020533
development/language/php/tips/getdate.1625401302.txt.gz · 最終更新: 2021/07/04 21:21 by hayashi