I need help with formatting date from mysql! with php!

Posted on 16th Feb 2014 by admin

Hello guys

*Note: this is a php question not MySQL question, please do not move it to mysql section! Thank you.

anyway, I have a record from the database as 2009-12-31 23:59:59

I needed to when ever I pull that record, I need to change it to mktime() format, so I can do so many things with it.
I tried to change it through preg_replace!



$str = "2009-10-13 11:30:15"; // an example only of the format data pulled from the DB!
$pat = '/(d{4})-(d{2})-(d{2}) (d{2}):(d{2}):(d{2})/';
$replace = 'mktime(4 ,5 ,6 ,2 ,3 ,1)';
echo preg_replace($pat, $replace, $str); // which give me the exact string of mktime(#,#,#,#,#,#)!


Please help me out!

Thank

Other forums