Member-only story
How to Get the Only Date from Timestamp in PHP
In this tutorial, we will learn how to get only date from timestamp in PHP. Timestamp or date-time object is very essential in creating dynamic web applications.
It helps us to know the exact time and store the time in our mysql database while inserting the data in the database or updating the data in the database.
I recommend you all to insert the timestamp in every table in your database while creating the applications.
It is often seen that we don’t have any particular date entry in our database but we need the exact date of the information we retrieve from the database.
As such, we can extract any date from the DateTime object from our database.
Also read, PHP difference between two dates in years, months and days
In order to extract or get only date from the timestamp, we have to follow the below methods
- strtotime()
- date()
strtotime():- This function converts a textual date or human-readable date into UNIX Timestamp.
date():- This function converts a timestamp into a human-readable date with year and month and date.
The parameters of the date() function are described below
- Y- The four-digit representation of the year.
- m- The number representation of all the months from January to December.