🔴 Advanced · Lesson 29
Date and Time
Date and Time
Working with Dates
PHP makes it easy to show, format and calculate dates using
date(), strtotime() and the DateTime class.Common Examples
echo date("Y-m-d"); // 2026-06-03
echo date("d/m/Y H:i"); // 03/06/2026 14:30
echo date("l"); // Wednesday
$ts = strtotime("2026-01-01");
echo date("d M Y", $ts); // 01 Jan 2026
Date Difference
$d1 = new DateTime("2026-01-01");
$d2 = new DateTime("2026-06-03");
$diff = $d1->diff($d2);
echo $diff->days . " days"; // 153 days
Summary
date()formats the current/any date;strtotime()parses text to a timestamp.DateTimewith diff() calculates differences between dates.
Dates के साथ काम करना
PHP
date(), strtotime() और DateTime class से dates दिखाना, format करना और calculate करना आसान बनाता है।Common Examples
echo date("Y-m-d"); // 2026-06-03
echo date("d/m/Y H:i"); // 03/06/2026 14:30
echo date("l"); // Wednesday
$ts = strtotime("2026-01-01");
echo date("d M Y", $ts); // 01 Jan 2026
Date Difference
$d1 = new DateTime("2026-01-01");
$d2 = new DateTime("2026-06-03");
$diff = $d1->diff($d2);
echo $diff->days . " days"; // 153 days
सारांश
date()current/कोई भी date format करता है;strtotime()text को timestamp बनाता है।DateTimeका diff() dates के बीच अंतर निकालता है।
💻 Live Code Editor
Is page ki language (PHP) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.