Display only Month of a Date
Moderator: General Moderators
Display only Month of a Date
I have a database (MySQL) filled with dates in the format YYYY-MM-DD and I need to somehow take a date from the database (lets say 2005-04-15) and show only the month. So the output would be just 04 . I am using PHP/MySQL and already have a recordset set up connecting to the database and all that I just need to somehow "filter" "sort" "format" ,whatever you want to call it, that date. Any and all help will be GREATLY appreciated.
Code: Select all
// Format: YYYY-MM-DD
$date = "2005-05-09";
list ( $year, $month, $day ) = explode ( "-", $date );
echo "Year: $year\nMonth: $month\nDay: $day";why not just use the date() function?
ex:
ex:
Code: Select all
$date = "2005-05-09";
$month = date("m",strtotime($date));
echo $month;Perfect. Thanks it works perfectly. Now I have another problem with the code below:
I started off with this:
And with your code I transformed it into this:
So now, rather than using "9" "10" and "11" it will use the values from the database. Only problem is I cant get it to repeat. It will only write the code of line 6 (in the 2nd php code box) one time rather than once for every date entry in the database.
I started off with this:
Code: Select all
$days = array(
$today=>array(NULL,'calendar-day',NULL,NULL.$today.'</span>'),
9=>array('#','calendar-linked',NULL,NULL.$evtDay.'</span>'),
10=>array('#','calendar-linked',NULL,NULL.$evtDay.'</span>'),
11=>array('#','calendar-linked',NULL,NULL.$evtDay.'</span>'),
);Code: Select all
$evtDate = $row_rsAppearances['Date'];
list ($evtYear, $evtMonth, $evtDay) = explode ("-", $evtDate);
$days = array(
$today=>array(NULL,'calendar-day',NULL,NULL.$today.'</span>'),
$linkDay=>array('#','calendar-linked',NULL,NULL.$evtDay.'</span>'),
);