Convert date to timestamp in PHP
Question:
How to convert date to timestamp in PHP? Answer:
$date = new DateTime($dateStr);
$timestamp = $date->getTimestamp();
Description:
To convert a date to a Unix timestamp in PHP first create a DateTime
object from your date. If you have a DateTime
object simply call its getTimestamp
method to get the timestamp value.
Reference:
DateTime getTimestamp reference
Share "How to convert date to timestamp in PHP?"
Related snippets:
- Add minutes to date time in PHP
- Add days to date in PHP
- Get same day in the next week in PHP
- Get time difference in minutes in PHP
- Convert date to timestamp in PHP
- Convert timestamp to DateTime in PHP
- Get the last day of a month from date in PHP
- Get the number of days between two dates in PHP
- Get yesterday's date in PHP
- Get tomorrow's date in PHP
- Get current time in PHP
- Get actual date in PHP
Tags:
date to timestamp, convert date string to Unix timestamp, convert DateTime to timestamp Technical term:
Convert date to timestamp in PHP