Snippet Name: Build Date Select Boxes
Description: A function that builds select boxes for the month,day,and year. It will default to mmddyyyy, current date, or specified date depending on the parameters.
Also see: » Convert UK Dates To mySQL Format Dates
» Delete files older than 'X'
» String to Date
» Month, Day, Year dropdown boxes
» Calculate date of Easter Sunday
» Define a schedule of holidays
» Calendar for any month any year
» Add and Subtract dates
» Basic PHP Calendar
» Convert Standard time to 24-hour time ...
» What Season Is It?
» Delete by date
» Days in month #2
» Days in month one
» Count days between dates
» Find days between dates one
Comment: (none)
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009
|
<?PHP
FUNCTION buildDate($name, $m, $d, $y) {
$date = DATE("m-d-Y",STRTOTIME("now"));
$date_array = EXPLODE("-",$date);
$now_m = "";
$now_d = "";
$now_y = "";
$month = '<select class="small" name="'.$name.'_month">';
$month .= '<option value="" selected disabled>mm</option>';
FOR ($i=1;$i<=12;$i++) {
IF ( $m != "" ) {
IF ( $m == $i ) {
$now_m = "selected";
}
}ELSEIF ( $m == "0" ) {
$now_m = "";
}ELSE{
IF ( $date_array[0] == $i ) {
$now_m = "selected";
}
}
$month .= '<option value="'.$i.'" '.$now_m.'>'.$i.'</option>';
$now_m = "";
}//END month for loop
$month .= '</select>';
$day = '<select class="small" name="'.$name.'_day">';
$day .= '<option value="" selected disabled>dd</option>';
FOR ($i=1;$i<=31;$i++) {
IF ( $d != "" ) {
IF ( $d == $i ) {
$now_d = "selected";
}
}ELSEIF ( $d == "0" ) {
$now_d = "";
}ELSEIF ( $d == $i ) {
$now_d = "selected";
}ELSE{
IF ( $date_array[1] == $i ) {
$now_d = "selected";
}
}
$day .= '<option value="'.$i.'" '.$now_d.'>'.$i.'</option>';
$now_d = "";
}//END day for loop
$day .= '</select>';
$year = '<select class="small" name="'.$name.'_year">';
$year .= '<option value="" selected disabled>yyyy</option>';
FOR ($i=GMDATE("Y"); $i <=SUBSTR(get330Date(),0,4); $i++) {
IF ( $y != "" ) {
IF ( $y == $i ) {
$now_y = "selected";
}
}ELSEIF ( $y == "0" ) {
$now_y = "";
}ELSEIF ( $y == $i ) {
$now_y = "selected";
}ELSE{
IF ( $date_array[2] == $i ) {
$now_y = "selected";
}
}
$year .= '<option value="'.$i.'" '.$now_y.'>'.$i.'</option>';
$now_y = "";
}//END year for loop
$year .= '</select>';
//-------------------------------------------
ECHO $month." ".$day." ".$year;
}//END buildDate function
// ------------------------------------
FUNCTION get330Date() {
RETURN DATE("Y-m-d", MKTIME(0, 0, 0, SUBSTR(GMDATE("Y m d"),5,2),
SUBSTR(GMDATE("Y m d"),8,2) + 330,
SUBSTR(GMDATE("Y m d"),0,4)))."<br />";
}
?> |