R
Rishtaara
PHP Fundamentals
Lesson 15 of 32Article16 min

Date/Time & Include

Use date() for formatted output and time() for Unix timestamps. DateTime class gives object-oriented date handling.

Date and Time

Use date() for formatted output and time() for Unix timestamps. DateTime class gives object-oriented date handling.

Real-life example: date() is a wall clock you can reformat — show 24-hour time, month names, or ISO dates.

date() and DateTime
<?php
echo date("Y-m-d H:i:s"); // 2026-07-24 10:30:00
echo date("l, F j, Y");   // Thursday, July 24, 2026

$dt = new DateTime("now", new DateTimeZone("Asia/Kolkata"));
$dt->modify("+7 days");
echo $dt->format("Y-m-d");
?>

Include and Require

include and require pull other PHP files into the current script. require stops with fatal error if missing; include only warns.

Use include_once / require_once to avoid loading the same file twice.

Real-life example: include is copying a shared recipe into tonight's menu — header.php on every page.

header.php and footer.php pattern
<?php
// index.php
$pageTitle = "Rishtaara PHP Course";
require "header.php";
?>

<main>
  <h1>Welcome to Rishtaara</h1>
</main>

<?php require "footer.php"; ?>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
  <title><?= htmlspecialchars($pageTitle ?? "Site") ?></title>
</head>
<body>