A quick search didn't return any results that seemed to fit what I was looking for so I come here asking for your help.
I am working on formatting a birthday. The problem is, the use has the ability to enter only some (or none) of the data. It is stored separately as day, month, and year.
Basically, based on the data present will determine how the date will be formatted and displayed back to the user.
My approach is:
#prepare birthday
$bday = new DateTime();
$bday->setTimezone(new DateTimeZone('America/New_York'));
$bday->setDate($row->birth_year,$row->birth_month,$row->birth_day);
if($row->birth_month && $row->birth_year && $row->birth_day){
//Full birthday entered
$display_bday = $bday->format('F j, Y');
} elseif($row->birth_month && !$row->birth_year && !$row->birth_day){
//Only a month
$display_bday = $bday->format('F');
} elseif($row->birth_month && $row->birth_year && !$row->birth_day){
//Only Month and year
$display_bday = $bday->format('F, Y');
}
I was wondering if there is a better way to accomplish this task. I guess I figure there has to be a better way. Thanks in advance. If I need to clarify anything please just ask!
edit: removed unnecessary code