PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Just wanna introduce myself to this forum first of all, as this is my first post ever... on this forum. So, Hi everyone!
Now to my problem....
I'm trying to retrieve data from a MySQL DB, where one of the fields is an event date, where it displays it as ex.) 16-08-04, but I want it to display it as example: Monday, August 16th, 2004. How do I do that?
$date = date retrieved from db
$exploded = explode("-",$date);
$stamp = mktime(0,0,0,$exploded[1],$exploded[0],$exploded[2]);
$pretty_date = (date('l, F jS, Y',$stamp); //the "l" is a lowercase "L"
This will also put the "th", "nd", and "st" after the day of the month - I'm not sure if the SQL way will do that.
Ok, I removed the first bracket, but now I get dates popping up as January 24th, 2007 , March 15th, 2033, etc... how do I remove that? I just want events for the CURRENT YEAR!
Well, you could find out what the current year is, and only return dates between 01-01-CURRENT_YEAR and 31-12-CURRENT_YEAR. Or I believe MySQL has a substring function (the sites down for some reason now) that could allow you to ensure the last two digits are of the current year. There might be some date functions in MySQL that are more suited to this as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Hmm, display the query with all variables parsed. Just echo it. Where is CURRENT_DATE defined? Is it a global variable or something in MySQL. If it's a global, it won't be parsed if you're in heredocs or quoting the query with ".
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.