proctk Posted August 20, 2007 Share Posted August 20, 2007 Hi I have a variable $dateTime which is set from a mysql query. The value will always be datetime as that is how the mysql column is set. I want to change the formating of the variable to return a value like august 19 at 3:30 pm any help or direction is excellent Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/ Share on other sites More sharing options...
wmguk Posted August 20, 2007 Share Posted August 20, 2007 http://uk.php.net/manual/en/function.date.php something like <?php date("F t at g:i a", $date_time) ?> will format to august 19 at 3:30pm it will be something like this, however i cannot test it Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-328551 Share on other sites More sharing options...
proctk Posted August 20, 2007 Author Share Posted August 20, 2007 it retuns this December 31 pm31 7:33 pm this should be 2007-08-20 00:05:10 unformated Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-328554 Share on other sites More sharing options...
wmguk Posted August 20, 2007 Share Posted August 20, 2007 hmm, ok, <?php date("F t - g:i a", $date_time) ?> is this any better? Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-328559 Share on other sites More sharing options...
AndyB Posted August 20, 2007 Share Posted August 20, 2007 http://ca.php.net/manual/en/function.date.php review example 439 to see exactly how to get 'words' into your dates. Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-328562 Share on other sites More sharing options...
proctk Posted August 21, 2007 Author Share Posted August 21, 2007 thanks for the help, do I need to reformat the date that is returned from the variable that is set from the myslq table Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329407 Share on other sites More sharing options...
dbillings Posted August 21, 2007 Share Posted August 21, 2007 You haven't showed us the value of the variable returned from your mysql table. So we can't know. Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329412 Share on other sites More sharing options...
proctk Posted August 21, 2007 Author Share Posted August 21, 2007 the example posted on the php website do not work when one of the lets used to express a date or time value is use here is what I have date("F t \a\t\ g:i a", $sentMessages['date_sent']); ?> which returns December 31 a 7:33 pm the value stored in the variable is 2007-08-20 00:05:10 thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329419 Share on other sites More sharing options...
Hypnos Posted August 21, 2007 Share Posted August 21, 2007 date() expects a unix time stamp as an input. If you're using PHP 5+, you can use strtotime to convert it to a unix time stamp. A unix time stamp is basicly the number of seconds since 01-01-1970. date("F t \a\t\ g:i a", strtotime($sentMessages['date_sent'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329426 Share on other sites More sharing options...
proctk Posted August 21, 2007 Author Share Posted August 21, 2007 thank you for the help its closer what you posted returns this August 31 a 12:05 am its not the correct result based on the above Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329428 Share on other sites More sharing options...
Hypnos Posted August 21, 2007 Share Posted August 21, 2007 Your date string wasn't right. t - Number of days in the given month. As in the maximum days of that month. date("F j \a\t\ g:i a", strtotime($sentMessages['date_sent'])); ?> Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329436 Share on other sites More sharing options...
proctk Posted August 21, 2007 Author Share Posted August 21, 2007 very close its returning the correct date but still leaving the t out value = August 20 a 12:05 am should be August 20 at 12:05 am Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329449 Share on other sites More sharing options...
proctk Posted August 21, 2007 Author Share Posted August 21, 2007 any ideas how to get the 't' to print in the date out put thank you Quote Link to comment https://forums.phpfreaks.com/topic/65766-formating-mysql-datetime/#findComment-329454 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.