Date and Time in PHP

 Date and Time in PHP


PHP provides built-in functions to work with date and time. You can format dates and times, calculate time differences, and perform other operations.

Example:


php


// get the current date and time

$date = date("Y-m-d H:i:s");

echo $date; // output: 2023-04-05 15:30:00


// calculate the time difference between two dates

$date1 = new DateTime("2023-01-01");

$date2 = new DateTime("2023-04-05");

$diff = $date2->diff($date1);

echo $diff->format("%a days"); // output: 94 days

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...