scotchegg78 Posted August 29, 2007 Share Posted August 29, 2007 hey guys quicky whats the best way to get a my mysql stored date in the format "2007-04-01" to output on screen with php help as April 2007. The day is not important, just the month and year in a readable fashion. thanks x Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/ Share on other sites More sharing options...
hostfreak Posted August 29, 2007 Share Posted August 29, 2007 http://php.net/date or http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337099 Share on other sites More sharing options...
scotchegg78 Posted August 29, 2007 Author Share Posted August 29, 2007 http://php.net/date or http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format forum helper? always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help? i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it. Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337112 Share on other sites More sharing options...
richardw Posted August 29, 2007 Share Posted August 29, 2007 Just to confirm, the exidting date is a string "2007-04-01" and not a timestamp or other date field format? Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337119 Share on other sites More sharing options...
hostfreak Posted August 29, 2007 Share Posted August 29, 2007 http://php.net/date or http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format forum helper? always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help? i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it. Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone. It always amazes me how people want things handed to them on a silver platter. If you want help, expect to be ready to help yourself first. You never asked for an example. You asked for the best way to accomplish something and I provided you reference to what I believed to be the best ways. Might I also note, I provided you with links to manuals from the languages you are using. It doesn't get any better than that (examples they offer etc). Aslo, might I add, per forum guidelines, it is ACTUALLY recommended to google it: http://www.phpfreaks.com/forums/index.php/topic,6264.0.html (I recommend you read them) Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337122 Share on other sites More sharing options...
scotchegg78 Posted August 29, 2007 Author Share Posted August 29, 2007 http://php.net/date or http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-format forum helper? always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help? i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it. Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone. It always amazes me how people want things handed to them on a silver platter. If you want help, expect to be ready to help yourself first. You never asked for an example. You asked for the best way to accomplish something and I provided you reference to what I believed to be the best ways. Might I also note, I provided you with links to manuals from the languages you are using. It doesn't get any better than that (examples they offer etc). your right, lets close the site, save money and all read manuals. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337125 Share on other sites More sharing options...
hostfreak Posted August 29, 2007 Share Posted August 29, 2007 your right, lets close the site, save money and all read manuals. What a petty argument. A better suggestion: Lets take help for what it is; help. If you don't like the help provided, fine. There is no need to act immature about it and make ignorant statments. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337128 Share on other sites More sharing options...
scotchegg78 Posted August 29, 2007 Author Share Posted August 29, 2007 Just to confirm, the exidting date is a string "2007-04-01" and not a timestamp or other date field format? rich its stored as date in mysql, and i belive its this format yes mate. I think the best way is to write some code using $year = substr($row_qryCompanyDetails['CompanyExpire'],0,4); $month = substr($row_qryCompanyDetails['CompanyExpire'],5,2); and then do some magic on it to compare and output the correct month string? Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337131 Share on other sites More sharing options...
jitesh Posted August 29, 2007 Share Posted August 29, 2007 PHP echo date("F Y",strtotime("2007-04-01")); Mysql SELECT DATE_FORMAT("2007-04-01",'%M %Y'); Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337132 Share on other sites More sharing options...
hostfreak Posted August 29, 2007 Share Posted August 29, 2007 Or yet another option: <?php $Date = "2007-04-01"; $Date_Arr = explode("-", $Date); $Month = date("F", mktime(0, 0, 0, $Date_Arr[1], 1, 0)); echo $Month . ' ' . $Date_Arr[0]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337145 Share on other sites More sharing options...
richardw Posted August 29, 2007 Share Posted August 29, 2007 I see you have two good options. Are you all set with the the output? Only asking because of the "compare and output the correct month string" comment. Best Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337365 Share on other sites More sharing options...
grimmier Posted August 29, 2007 Share Posted August 29, 2007 this is what i use. <?php echo date("M, Y",strtotime($date)); // if $date was "2007-08-29" //prints Aug, 2007; // or use this echo date("F, Y",strtotime($date)); //prints August, 2007; //replace the $date with whatever the result from your query is for the date. ?> short and sweet. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337432 Share on other sites More sharing options...
trq Posted August 29, 2007 Share Posted August 29, 2007 Its much more efficient to use mysql's DATE_FORMAT function. This way you only actually recieve the data you want, formatted how you want it allready. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337435 Share on other sites More sharing options...
roopurt18 Posted August 30, 2007 Share Posted August 30, 2007 forum helper? always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help? i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it. Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone. If a mod feels I'm out of line, by all means edit this post, but this response was way out of line. You asked a question, someone gave you the information to solve your problem with two different methods. In the PHP documentation, all it took was a ctrl + f -> "mysql" and you get this code: // format MySQL DateTime (YYYY-MM-DD hh:mm:ss) using date() function datetime($syntax,$datetime) { $year = substr($datetime,0,4); $month = substr($datetime,5,2); $day = substr($datetime,8,2); $hour = substr($datetime,11,2); $min = substr($datetime,14,2); $sec = substr($datetime,17,2); return date($syntax,mktime($hour,$min,$sec,$month,$day,$year)); } The link to the MySQL documentation contains six examples less then half a page down. Both of them were obtainable by you in less than 15 seconds, yet you decided to take that time to reply and throw help back in someone's face? It's irrelevant that the date is already returned in a query as you can always modify the query to return different or additional information. As thorpe pointed out, it's almost always more efficient to have the database engine perform the work for you. I suggest you learn some basic manners and how to take a little initiative before you attempt to do much programming; if you do not learn how to apply a general example to your specific problem you will extremely hamper your ability to become a proficient programmer and problem solver. Quote Link to comment https://forums.phpfreaks.com/topic/67208-convert-mysql-date-format-2007-04-01-to-april-2007-output/#findComment-337452 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.