Skip to content

Instantly share code, notes, and snippets.

@furkanmustafa
Created January 27, 2013 15:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save furkanmustafa/4648867 to your computer and use it in GitHub Desktop.
Save furkanmustafa/4648867 to your computer and use it in GitHub Desktop.
Date Picker Select Generator for HTML & PHP
<select name="year">
<option value="">Year</option>
<?php for ($year = date('Y'); $year > date('Y')-100; $year--) { ?>
<option value="<?php echo $year; ?>"><?php echo $year; ?></option>
<?php } ?>
</select>
<select name="month">
<option value="">Month</option>
<?php for ($month = 1; $month <= 12; $month++) { ?>
<option value="<?php echo strlen($month)==1 ? '0'.$month : $month; ?>"><?php echo strlen($month)==1 ? '0'.$month : $month; ?></option>
<?php } ?>
</select>
<select name="day">
<option value="">Day</option>
<?php for ($day = 1; $day <= 31; $day++) { ?>
<option value="<?php echo strlen($day)==1 ? '0'.$day : $day; ?>"><?php echo strlen($day)==1 ? '0'.$day : $day; ?></option>
<?php } ?>
</select>
@DevJacobZhang
Copy link

hello ! if month:3 day just have 29, how to write ? when user choice month ,day will change.

@furkanmustafa
Copy link
Author

@DevJacobZhang, this one was just for a simple input. It's better to use some javascript date picker for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment