How do I convert different formatted dates in timestamp in php ? I have date in this August 2nd, 2015 format and I need to conver it to timestamp so that I can make comparisons. Thanks in advance.
- secure.php.net/DateTimeCharlotte Dunois– Charlotte Dunois2016-12-12 17:41:18 +00:00Commented Dec 12, 2016 at 17:41
Add a comment |
2 Answers
strtotime() can and will bite you if you use it with date formats that are unclear, eg: 11/10/12.
Learn to love DateTime:createFromFormat() and be explicit in your parsing formats.
var_dump(DateTime::createFromFormat("d/y/m", "11/10/12")); object(DateTime)#1 (3) { ["date"]=> string(26) "2010-12-11 10:02:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(17) "America/Vancouver" }