codescracker


php

PHP Date and Time



« Previous Tutorial Next Tutorial »


Date and time in PHP, plays an important role, where date and time matter. You can use date() function available in PHP to format a date and/or time. Here is the general form to use date() function to format a timestamp to a more readable date and time in PHP:

date(format,timestamp)

Here, format is requred, specifies the format of the timestamp. And timestamp is an optional, specifies a timestamp.

PHP Date and Time Example

Let's look at the following example which formats today's date in three different ways:

<!DOCTYPE html>
<html>
<body>

<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";
?>

</body>
</html>

Here is the sample output produced by the above PHP script:

Automatic Update Copyright Year using PHP

<!DOCTYPE html>
<html>
<body>
<?php echo "codescracker.com "; ?>
@ 2007-<?php echo date("Y")?>

</body>
</html>

Here is the sample output produced by the above PHP script:

codescracker.com @ 2007-

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test