samoi Posted October 19, 2009 Share Posted October 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/178174-solved-i-need-help-with-formatting-date-from-mysql-with-php/ Share on other sites More sharing options...
Philip Posted October 19, 2009 Share Posted October 19, 2009 You could do this with MySQL... just using UNIX_TIMESTAMP() SELECT UNIX_TIMESTAMP(date_time_column), another_column FROM table WHERE id = 2 Link to comment https://forums.phpfreaks.com/topic/178174-solved-i-need-help-with-formatting-date-from-mysql-with-php/#findComment-939458 Share on other sites More sharing options...
samoi Posted October 19, 2009 Author Share Posted October 19, 2009 You could do this with MySQL... just using UNIX_TIMESTAMP() SELECT UNIX_TIMESTAMP(date_time_column), another_column FROM table WHERE id = 2 Thank you very much! That helps alot! Link to comment https://forums.phpfreaks.com/topic/178174-solved-i-need-help-with-formatting-date-from-mysql-with-php/#findComment-939495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.