Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Increase Year Range in Drop Down

In CakePHP, if i keep a table field type as date, then it shows dropdown with month, day and year. However, the year range starts from 1990 only, how can I change it to start from 1900?

like image 880
Aditya P Bhatt Avatar asked May 02 '11 09:05

Aditya P Bhatt


1 Answers

You can use minYear and maxYear options of an input like this:

<?php

echo $this->Form->input('birth_dt', array(
    'label' => 'Date of birth', 
    'dateFormat' => 'DMY',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18 ));

?>

Reference to cakePHP Cookbook

FYI: If current year is 2017 date('Y') - 70 will be 1947 [2017 - 70 = 1947].

like image 196
Headshota Avatar answered Sep 19 '22 04:09

Headshota