How to use Date and Time in PHP

tutorial and example
tutorial and example

HOW TO USE DATE AND TIME IN PHP:

PHP time and date function  informs us about current date and time. it can be manipulated also.

How time() function works:

The time() function would work by our server time and can be changed. It returns integer but not the argument. Date and time are stored in computer in UNIX Timestamp format. That calculates time in number of seconds on GMT ( greenwich mean time) i.e  January 1,1970.

Syntax:

Output: 1532423507

EXAMPLE:

How date() function works:

In PHP, date() function shows day, month and year altogether. Date and time are stored in computer in UNIX Timestamp format. That calculates time in number of seconds on GMT ( greenwich mean time) i.e January 1,1970.

Syntax:

Output: 24/07/2018

Methods for PHP Date and Time:

  1. checkdate(): this clears the date and year exists or not.

Example:

Output:

bool(false)
bool(false)
bool(true)

2. dateadd(): this method is used to add the days, months, years to the date.

Example:

Output: 2013-04-24

3. datecreate(): it returns new datetime .

Syntax:

Example:

Output: 2013/03/15 23:40+01:00

Recasting a Time Stamp with getdate() function:

The function getdate()  takes a time stamp and  associative array is returned and all the information about date is embedded in it. the time stamp is optionally working instead current time stamp is used that returned by time().

Example: