PHP Function Mktime() Tutorial with Example

The mktime() returns the Unix time stamp of the given argument. The result time stamp contains the number of seconds between the unix time stamp (January 1 1970 00:00:00 GMT) and the that date. If you will not provide any arguments then value will be set to the current value according to the local date and time.
On success mktime() function return the Unix Timestamp otherwise if any argument is invalid it will return FALSE.

Syntax is of mktime() php method


hour Optional. Specifies the hour
minute Optional. Specifies the minute
second Optional. Specifies the second
month Optional. Specifies the numerical month
day Optional. Specifies the day
year Optional. Specifies the year.
is_dst Optional. Set this parameter to 1 if the time is during daylight savings
time (DST), 0 if it is not, or -1 (the default) if it is unknown.

Below Code is used to convert Time stamp into MySQL type DATE Format

Some Useful Function of DateTime period

Current year

The code below covers the period from January 1st to 00:00:00 today:

Last year

The below code covers date between from January 1, at 00:00:00 to 31 December at 23:59:59:

This Month

The below code covers the period between from the first day of the current Month to now:

Last 30 days or Last Month

The code below covers the period from 30 days ago to now:

How to get This week DateTime

I will assumes the first day of the week is Monday. It covers the period from Monday morning at 00:00:00 to now:

Last week(From Monday to Sunday)

Below code covers the period from the Monday at 00:00:00 to the following Sunday at 23:59:59:

How to get Last 24 hours Date Time

The code below covers the past 24 hours so far:

How to get Yesterday Date

Below covers the period from yesterday at 00:00:00 to 23:59:59 yesterday: