In this example you will learn, how to Convert a Date to Timestamp in PHP. You can use the PHP strtotime() function to convert any textual datetime into Unix timestamp.
The following example demonstrates how this function actually works:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $date1 = "2019-05-16"; $timestamp1 = strtotime($date1); echo $timestamp1; // Outputs: 1557964800 $date2 = "16-05-2019"; $timestamp2 = strtotime($date2); echo $timestamp2; // Outputs: 1557964800 $date3 = "16 May 2019"; $timestamp3 = strtotime($date3); echo $timestamp3; // Outputs: 1557964800 ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.