1

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.

1

2 Answers 2

2
<?php echo $test = strtotime("August 2nd, 2015"); echo date("Y-m-d",$test); ?> 

So use strtotime("August 2nd, 2015");

Sign up to request clarification or add additional context in comments.

Comments

1

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" } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.