Convert String Into Timestamps in PHP

In this tutorial, we will try to convert string into timestamps in PHP by using strtotime() function. This function will convert string such as "Today" into timestamps and shows us the value of today in the form of date after converting it into timestamps. So, let's do it!

The strtotime() function can be used by you if you want to make some kind of current date on your website or maybe the date from 72 hours ago. It's very useful when you need it.
Before going through the coding, please take a look at these properties below:

d=day of month(numeric)
D=day(Thu)
I=Day(Thursday)
F=month(December)
M=month(Dec)
m=month(12)
Y=year
h=hour(12-hour format)
H=hour(24-hour format)
a=am or PM
i=minute
s=seconds

Done? Now, let's take a look to the coding and let it run...!

<?php
echo "<p>Today: ". date('D d M Y', strtotime("today")) ."</p>";
echo "<p>Tomorrow: ". date('D d M Y', strtotime("tomorrow")) ."</p>";
echo "<p>48 Hours Ago: ". date('D d M Y', strtotime("48 hours ago")) ."</p>";
echo "<p>Yesterday: ". date('D d M Y', strtotime("yesterday")) ."</p>";
echo "<p>Next Monday: ". date('D d M Y', strtotime("next monday")) ."</p>";
?>

Let the code runs and you will understand it. Thank you!

Labels: , , , ,