I currently code a symfony project that requires saving many dates below 1091. In MySQL, DateTime recording is good. But when I refreshed the page, the value displayed is wrong. I use a datetime field including the following code:
$builder->add(
'datetimepublish',
DateTimeType::class,
[
'model_timezone' => date_default_timezone_get(),
'view_timezone' => date_default_timezone_get(),
'widget' => 'single_text',
'format' => 'dd/MM/yyyy HH:mm',
'label' => 'Date et heure',
'attr' => [
'placeholder' => 'Date et heure',
],
]
);
This behavior would be a 'normal', I searched a bit in the vendor, and I think I find when it did that, the DataTransformer. How to cure it?
I have the same issue here and discovered that it's most likely you work on a 32-bit system and symfony somewhere uses a timestamp representation of the date, which php on 32-bit systems can't handle if the year is one before 1902.
It's amazing.
#see:
https://github.com/symfony/symfony/issues/5227
Related
Hi I've got a problem with year format on DateType, let take a look on this image
I want to change year from AD convert to BE in Thailand format
So It's will look like this AD = 2017 convert to BE = 2560
Is anyone know how to change this thing
and this is my form type code.
->add('birthday', DateType::class, [
'required' => false,
'widget' => 'single_text',
'label' => 'Birthdate',
])
You'll likely want to use an external plugin to manage this as the Symfony default won't handle conversion of "base year."
Something like this will be where I'd look: https://github.com/jojosati/bootstrap-datepicker-thai/blob/thai/README-thai.md
And then in your builder object, I'd add a class to select the thai datepicker elements:
$builder->add('birthday', 'text', array(
'attr' => array(
'class' => 'thai-datepicker') //for example
)
);
I have a form element in a ZF2 application that uses DateSelect to allow a user to enter their date of birth. Currently the fields are shown in the order d-m-y. I would like to reverse this order so it is displayed as y-m-d. I have come across posts on SO that recommend changing the locale in PHP to change the order but that is not an option for me. I have also tried
$this->add(array(
'type' => 'Zend\Form\Element\DateSelect',
'name' => 'dob',
'options' => array(
'label' => 'Date of Birth',
'create_empty_option' => true,
'pattern' => $this->options['isMobile'] ? 'd MMM y' : 'd MMM y',
'empty_options' => array(
'day' => 'DD',
'month' => 'MM',
'year' => 'YYYY',
),
'allowLabelHTML' => TRUE,
'required' => true,
)
));
$this->get('dob')->setFormat('Y-m-d');
Which was an accepted answer to another SO question but that produces an internal server error for me. I would be surprised if this is not possible, maybe using an helper file but I cannot find anything on the web to suggest how, apart from the above and changing the locale. Can anyone help with this?
You get fatal error because method setFormat() does not exist in Zend\Form\Element\DateSelect.
I don't think it is possible to achieve this without writing own view helper.
Zend\Form\Element\DateSelect is based on locale settings, so you can pass locale short code as parameter to view helper, so order of elements will be proper for provided region.
This view helper takes 3 parameters $this->formDateSelect($element, $intlFormat, $locale), so you use it like this:
echo $this->formDateSelect($form->get('dob'), \IntlDateFormatter::LONG, 'en_Gb');
or...
echo $this->formDateSelect()->setLocale('en_Gb')->render($form->get('dob'));
or... you can change locale settings in your php.ini file
intl.default_locale = en_Gb
I am using a DateControl widget by Kartik in my Yii2-powered system. The widget correctly saves the time I've selected. However, when I tried to update the data, it just always shows "12:30" as the time and not the time from the database. I am still new to Yii2 and I there's not much information on the Internet regarding this issue. Thank you for the help!
Code for my form:
<?= $form->field($model, 'class_start_time')->widget(DateControl::classname(), [
'type'=>DateControl::FORMAT_TIME,
])
?>
<?= $form->field($model, 'class_end_time')->widget(DateControl::classname(), [
'type'=>DateControl::FORMAT_TIME,
])
?>
Code for the config:
'displaySettings' => [
Module::FORMAT_DATE => 'dd-MM-yyyy',
Module::FORMAT_TIME => 'HH:mm a',
Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss a',
],
// format settings for saving each date attribute (PHP format example)
'saveSettings' => [
Module::FORMAT_DATE => 'php:U', // saves as unix timestamp
Module::FORMAT_TIME => 'php:H:i:s',
Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
],
I found the solution. The displaySettings should be hh:mm a and not HH:mm a. There is a mismatch in the format which causes the display to be in error when the time is in PM (or greater than 12:00:00).
I am using datepicker in yii and I want to disable the previous dates on the calendar to avoid picking them.
Here's my code:
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'arrival_date_as_per_recorded_travel',
'name'=>'arrival_date_as_per_recorded_travel',
'value'=>$eta_date_formatted,
// additional javascript options for the date picker plugin
'options'=>array(
'startDate'=>date("yy-mm-dd"),
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
'changeMonth'=>'true',
'changeYear'=>'true',
'yearRange'=>'2013:2100',),
'htmlOptions'=>array(
'id'=>'arrival_date_as_per_recorded_travel',
'style'=>'height:20px;width:150px',
'value'=>$eta_date_formatted,
'onblur'=>'if(this.value=="")this.value=""'
),
));
As for Yii2 (added this as answer as the question is not tagged under yii 1.x)
<?php
use yii\jui\DatePicker;
?>
<?=
DatePicker::widget([
'name' => 'to_date',
'dateFormat' => 'dd/MM/yyyy',
'clientOptions' => [
'minDate' => 0
]
])
?>
change your options with the following code
'options'=>array(
'startDate'=>date("yy-mm-dd"),
'minDate'=>'0', // this will disable previous dates from datepicker
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
'changeMonth'=>'true',
'changeYear'=>'true',
'yearRange'=>'2013:2100',),
'minDate'=>'0' will disable the previous dates...
You can take look of Jquery Date Picker API (minDate)
Hope it may help you...
I have tried previous answers but nothing worked.
Here is how i solved this
The minDate is not found in the documentations https://www.malot.fr/bootstrap-datetimepicker/
There is something like minDate no it's called startDate but it accepts only Date.
startDate Date. Default: Beginning of time The earliest date that may be selected; all earlier dates will be disabled. as in Offical documentations.
So here you go.
<?php
$now = new DateTime();
echo $form->field($data['model'], 'expire_date' ,
['template' =>
'{label}<p class="sub-label">' . \Yii::t("main","After this date people won't be able to bid on this job no more.").'</p> {input}{error}{hint}'])
->widget(DateTimePicker::classname(),
[
'options' => [
'placeholder' => \Yii::t("main","Enter a date..."),
'autoComplete' => 'off',
],
//'convertFormat' => true,
'language' => "Yii::$app->language;",
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd hh:ii:ss',
'startDate' => date_format($now, 'Y-m-d'), //startDate Date. Default: Beginning of time The earliest date that may be selected; all earlier dates will be disabled.
]
]);?>
Adding the following to your options array should help.
minDate: new Date(),
I have created a field for publish date (with time), but I found only date formating. My time field is under my date field and it looks strange (for me), like this:
[DAY] [MONTH] [YEAR]
[HOURS]:[MINUTES]
How can i format it like this?
[DAY] [MONTH] [YEAR] - [HOURS]:[MINUTES]
There it is, what I now have in my Form builder:
$builder->add('published', 'datetime', array('label' => 'Date of publish', 'date_format' => 'ddMMMMyyyy', 'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'), 'invalid_message' => 'Date is not valid',))
PS: I'm using selection.
I have had the same problem once and solved it using the answer of this question:
Form theming datetime widget Symfony 2.
Also, find more info on the matter by browsing the following section of the Symfony2 official documentation.
How to customize Form Rendering.