ShaolinF Posted May 28, 2011 Share Posted May 28, 2011 I have a MySQL column which holds the date in DATETIME format. When I pull it and try and format it in php using the DATE function the times are wrong. See code below: <?php print date("d/m/y @ G:H:s A", strtotime($pt->transaction_date)); ?> Anyone know why this is the case ? Quote Link to comment https://forums.phpfreaks.com/topic/237718-wrong-date/ Share on other sites More sharing options...
gristoi Posted May 28, 2011 Share Posted May 28, 2011 Instead of passing the datetime and then running another function to reformat, try using the Date_format(mydateField, 'd/m/Y H:i:s') Within your query. The main reason you use a datetime in mysql is that it has an enormous array of functions that can be run against it, one of them Being formatting. Quote Link to comment https://forums.phpfreaks.com/topic/237718-wrong-date/#findComment-1221605 Share on other sites More sharing options...
Pikachu2000 Posted May 28, 2011 Share Posted May 28, 2011 How is it wrong, doesn't it match what is in the DB? And why would you use php to do that rather than using MySQL's DATE_FORMAT() function? Quote Link to comment https://forums.phpfreaks.com/topic/237718-wrong-date/#findComment-1221608 Share on other sites More sharing options...
ShaolinF Posted May 28, 2011 Author Share Posted May 28, 2011 doh, forgot about the mysql function. thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/237718-wrong-date/#findComment-1221614 Share on other sites More sharing options...
xyph Posted May 28, 2011 Share Posted May 28, 2011 Also, in case you NEED to use PHP's date functions for some reason, you can always return a date as a unix timestamp by using UNIX_TIMESTAMP(`column`) Quote Link to comment https://forums.phpfreaks.com/topic/237718-wrong-date/#findComment-1221618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.