Jump to content

[SOLVED] I need help with formatting date from mysql! with php!


samoi

Recommended Posts

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 you all

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.