CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · November 15, 2018

PHP Convert Text Date to MySQL Date

Posted on Wednesday, June 30, 2010 @ 07:49:10 PM CDT by David Yee [] [read 2986 times]

 
PHP Tips and Code Examples
In PHP, let's say you want to convert the text string "July 1, 2010" to the MySQL date format, you would use two functions- strftime() and strtotime().

strftime() takes 2 arguments- first is the date format, and for MySQL our format would be: '%Y-%m-%d'. The second argument is the integer timestamp- that's where the "magical" function strtotime() comes in. It will take a date text string and convert it into the timestamp integer value we need.

Thus, to convert "July 1, 2010" to "2010-07-01", the PHP code would be:

$mysql_date = strftime('%Y-%m-%d', strtotime('July 1, 2010'));



Please rate this article or post a brief review of PHP Convert Text Date to MySQL Date or comment on benchmark/performance, features, availability, price or anything else regarding PHP Convert Text Date to MySQL Date. Thanks!

PHP Convert Text Date To MySQL Date Rating: 2.8/5 (11 votes cast)

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title:
Comment/Review: