2

I am using CakePHP 2.6.x to create a simple input for type date:-

echo $this->Form->input('datetest', array(
    'label' => false, 
    'type' => 'datetime',
    'dateFormat' => 'YMD', 
    'minYear' => date('Y') - 70, 
    'maxYear' => date('Y') + 10, 
    'selected' => '2012-02-23')
);

This input returns the date in the format dd.mm.yyyy hh:ii:-

<div class="input datetime">
  <input id="ArticleDatetest" class="datetime" type="text" value="23.02.2012 00:00" autocomplete="off" maxyear="2025" minyear="1945" name="data[Article][datetest]">
</div>

The expected date format is yyyy-mm-dd hh:ii. What I am doing wrong?

2 Answers 2

1

First, change 'type' => 'datetime' to 'type' => 'date',

Second, you use browser html5 native date picker, wich show you your system datetime format. if you submit form data on your controller data will be in 2015-06-22 format.

Try here

But, this input type is not suported by IE , Firefox, etc.

Solution, use JS date picker and change 'type' => 'text'

Sign up to request clarification or add additional context in comments.

Comments

1

This works very well in CakePHP 3:

<?pho echo $this->Form->text('proposal_date', ['type'=>'date', 'value'=>$project->proposal_date->i18nFormat('yyyy-MM-dd')]); ?>

or you can use the solution https://stackoverflow.com/a/35895954/3813117 which is:

<?
$this->Form->templates(
  ['dateWidget' => '{{day}}{{month}}{{year}}']
);
  echo $this->Form->input('approval_date', ['type' => 'date']); ?>

It uses the native date selector of the browser. Works with Firefox, Chrome, Edge.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.