• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

PHP Date and Time

darkshadow

Influencer Marketing Manager
D Rep
0
0
0
Rep
0
D Vouches
0
0
0
Vouches
0
Posts
157
Likes
183
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
In this tutorial, we are going to learn about PHP Date and Time. Date and time are part of our everyday lives. PHP also provides this tools to make it work the dates and time easier. These functions allow you to get the date and time from your server where the PHP scripts are running. Then, you can use these functions to format the date and time in some ways.

Note: These function it depends on your settings of your server.

Installation: No need installation for these functions.

The PHP Date() Function

The PHP date() function formats a timestamp, so they are more likely human readable.

Syntax

date

(

format,

timestamp)

format - This is required field and the timestamp must be in specific format.
timestamp - This is optional field and it also specific timestamp and the current date and time is default.

Simple Date

Here are commonly used of characters for dates:

d - stand for the days of the month (01 - 31)
m - stand for a month (01 - 12)
Y - stand for a year; like (2010) (four digits)
l (this is lowercase of L) - stand for the days of the week

And, there are other characters can also be used for adding additional format in dates like "/", ".", or "-".

Example

This is the image result of the code below:
1_10.png

  1. <?php
  2. echo

    "Today is "

    .

    date

    (

    "l"

    )

    .

    "<br>"

    ;
  3. echo

    "The date today is "

    .

    date

    (

    "Y/m/d"

    )

    .

    "<br>"

    ;
  4. echo

    "The date today is "

    .

    date

    (

    "Y-m-d"

    )

    .

    "<br>"

    ;
  5. echo

    "The date today is "

    .

    date

    (

    "Y.m.d"

    )

    ;
  6. ?>

Another example, these function used to automatic update the copyright year of your website.
This is the image result of the code below:
untitled_5.png

break
Copyright &copy; <?php

echo

date

(

"Y"

)

;

?>

, Free source code, tutorials and articles

Simple Time

Here are commonly used of characters for times:

h - stand for 12-hour format (01 - 12)
i - stand for minutes (00 - 59)
s - stand for seconds (00- 59)
a - stand for Ante meridiem and Post meridiem (am or pm)

Example

This is the image result of the code below:
12.png

  1. <?php
  2. echo

    "The default time is "

    .

    date

    (

    "h:i:s a"

    )

    ;
  3. ?>

Date and Time Example

This is the image result of the code below: Date and Time codes.
a_0.png

  1. <?php
  2. echo

    "The date today is "

    .

    date

    (

    "Y-m-d"

    )

    .

    " and the time is "

    .

    date

    (

    "h:i:s a"

    )

    ;
  3. ?>

As of now this is the basic syntax of PHP Date and Time. As we go on we will teach you on how to create PHP Include Files one by one.

So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you.

 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,499

349,924

349,934

Top