Date Of Birth - Drop Down Box - Function

Started on the old forum in April 2011 · view the original in the archive · old links redirect here

#date #drop-down-box #function

1 reply · 5,837 views · started 15 years ago · 1 min read

2 participants
something else Fellow · 2,296 posts #1

Here a drop box function i made for getting date of birth 🙂

it saves having loads of days/months/years wrote on a page and also can select the last date entered if needed.

function dateOfBirth($day,$month,$year) 
{ 
//Day 
  $age = 'Dob: <select name="day">'; 
for ($i = 1; $i <= 31; $i++) { 
if($day==$i) $sel=' selected="selected"'; else $sel=''; 
  $age .= '<option value="'.$i.'"'.$sel.'>'.$i.'</option>'; 
} 
  $age .= '</select>'; 

//Month 
  $age .= '<select name="month">'; 
for ($i = 1; $i <= 12; $i++) { 
$name = date( 'F', mktime(0, 0, 0, $i) ); 
if($i<10) $i = '0'.$i; 
if($month==$i) $sel=' selected="selected"'; else $sel=''; 
  $age .= '<option value="'.$i.'"'.$sel.'>'.$name.'</option>'; 
} 
  $age .= '</select>'; 

//Year 
  $age .= '<select name="year">'; 
for ($i = date("o"); $i >= date("o")-100; $i--) { 
if($year==$i) $sel=' selected="selected"'; else $sel=''; 
  $age .= '<option value="'.$i.'"'.$sel.'>'.$i.'</option>'; 
} 
  $age .= '</select><br/>'; 

return $age; 
}

Usage:

echo '<form action="index.php">';
echo dateOfBirth(29,04,1985);
echo '<input type="submit" value="Update Birthday"/></form>';
morse Senior · 364 posts #2

Thats PHP mktime() function logically used. Thanks, this is really a code space savior 🙂

tinyurl.com/earnbymobile Easy earning for Indians

Alternative mobile advertising network .. Minimum 100 USD pay / NET15 pay cycle, Good Brand, Best targeting for Android goo.gl/6vub3

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close