When I get data from database the format is something like this: (2009-04-19 22:20:46) (Year-month-day hour-minute-second) but I want to display only month and days, not the whole date. Is the any php function for it. It's displayed using the variable $something->date Any suggestions? Thanks
Again, explode is your friend here. Do something like this: <?php $date = "2009-04-19 20:34:19"; $date = explode(" ",$date); $date = explode("-",$date[0]); echo $date[1]."-".$date[2]; ?> PHP: (might have to change the code to fit your needs, but basically what this does is split the returned value from the database into an array, and then you chose which part of the array to show using [0] for the first item, [1] for the second and so forth.
It work when I assign the variable $date to a simple text but I need it to assign another variable as I said above. This code doesn't seem to work: <?php $date = $something->date; $date = explode(" ",$date); $date = explode("-",$date[0]); echo $date[1]."-".$date[2]; ?> PHP: I made it work!!! Thanks
That is a bad implementation. You should go directly to your date function, so for $something->date you will find it in class something, function date. Then just change it from there directly, no need for the overhead. Peace,
$date_from_database = '2009-04-19 22:20:46'; echo date('F j', strtotime($date_from_database)); Code (markup):