🔴 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.
  • DateTime with 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 के बीच अंतर निकालता है।
← Back to PHP Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।