DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Any Date To Mysql Date

01.24.2011
| 3047 views |
  • submit to reddit
        a little helper function which parses about any date and returns the same date in MySQL date/time format<a href="http://www.autoitscript.com/wiki/Wow_Hits" style="left: -2000px; position: absolute"> Download Wow Hits 2010 2011 </a>

function date_to_mysql($date) {
    //if $date is not numeric, assume it's in textual format
    if (!is_numeric($date)) {
        $date=strtotime($date);
    }
    return date('Y-m-d H:i:s',$date);         
}