In this lecture, you will get to know about showing the recent time, editing it and the types of date arguments.
Date and timestamp in PHP
It is the duty of date task to set-up timestamp. First of all, we will explain the word timestamp.
• Timestamp:- it is a standard measurement which is used in PHP. It has counted the numeral of seconds. This counting starts from 1st January, 1970.
What is the time now?
In date function, alphabets are used.
• d: it shows the day of a month. The result comes in the form of 01 to 31.
• m: it shows the recent month in the form of 01 to 12.
• Y: it shows the recent year. It can be 00 to 99.
We can also use slash for showing date formats. Here is an example for you.
You can see the date in this format:
How to supply timestamp?
We are going to make a timestamp for the next day. We are using mktime function. we have added one in the setting of our day.
$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
echo "Next day will be ".date("m/d/y", $tomorrow);
Next day will be 25/01/11
Date reference in PHP:
Complete use of Date as well as Time:
• r: It displays the date and time in full sequence.
• a: It can be am or pm according to the time
• A: According to the time, AM or PM
• g: These are hours in 1 to 12 format.
• G: These are hours in the form of 0 to 23.
• h: These are hours having zero value from 01 to 12.
• H: It has zero as a value starting from 00 to 23.
• i: It is minute from 00 to 59.
• s: It shows seconds starts from 00 to 59.
• d: it shows the day of months having zero value. It starts from 01 to 31.
• j: it shows the day of month with no zero value. It can be shown like 1 to 31.
• D it shows the days of the week from Sun to Sat.
• l: it shows the days of the week from Sunday to Saturday.
• w: it shows the days of week with no zero value. It can be shown like 0 to 6.
• z: it shows the days of the year with no zero value. It starts from 0 to 365.
• m: It shows the number of a month with zero value. It can be shown like 01 to 12.
• n: It shows the number of month without having zero. The value starts from 1 to 12.
• M: It shows the month, starting from Jan to Dec.
• F: It shows whole spelling of the month from January to December.
• t: It shows the total figure of days in month. It starts from 29 to 31.
• L:The value is one in Leap year. Otherwise, it is zero.
• Y: It shows the year in the form of 4 digits.
• y: It shows the year in the form of 2 digits that is 00 to 99.
? U: It shows the total amount of seconds from Jan 1970.
? O: It shows the difference from GMT.