My code is in PHP Laravel. And I tried to create a table in font-end which allow user to select my_date information from the drop-down calendar. Then, in back-end, I tied to save the table information into database via migration. But why the date information cannot be saved into mySQL database?
In config/database.php I already have
'strict' => false,
In index.blade.php file
<input id="my_date" type="text"
class=...
name="record[my_date]"
value="{{isset($project)&&isset($project->my_date)?$project->my_date->format('Y-m-d'):null}}"
placeholder="{{resolve('translate')->getWord('My Date')}}"
>
In migration
$table->dateTime('my_date');
I saw from this pots --> Date not being saved to mySQL datebase with laravel
And I tried --> I didn't get any error. Just when I delete & php artisan migrate & fill the font-end table again, there is still no date information being saved.
$table->dateTime('my_date')->format("Y-d-m");
I saw from this post --> After upgrade to laravel 5.3 error invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00'
And I tried --> no error, but still, no date information being saved.
$table->dateTime('pcmm_shipment_date')->default(NOW());
I also tried --> no error, but still, no date information being saved.
$table->datetime('expires_at')->nullable($value = true);
public function storeMyData(Request $request)
{
//validate
$validator = Validator::make($request['record'],
[
'project_id' => 'required',
'my_date' => 'required',
]
);
...
}
You can use useCurrent like so:
$table->timestamp('my_date')->useCurrent();
From the Laravel file vendor/laravel/framework/src/Illuminate/Database/Schema/ColumnDefinition.php it defines it as:
Set the TIMESTAMP column to use CURRENT_TIMESTAMP as default value
Related
when i try to make stricton value to TRUE then it shows error Error Number: 1364 Field 'modified_at' doesn't have a default value" and when try to make it FALSE then it shows error
Variable 'sql_mode' can't be set to the value of 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( ##sql_mode'
SELECT GET_LOCK('ad3549572403a9c71bea1109d26f4b48', 300) AS ci_session_lock
when the value is true, everything is working but i need to refresh to make error: "Error Number: 1364 Field 'modified_at' doesn't have a default value" gone.
please help me to overcome this fault.
thank uu!
Here is the screenshot of the errors:
enter image description here
enter image description here
Make this column nullable.Beacuse here modified_at is not nullable.When you a save a row data you passed every element but you didn't save any data into modified_at. so make this column nullable.
$table->date('modified_at')->nullable();
If you haven't enough data then
php artisan migrate:refresh
If you have enough data on database & don't wabt to refresh it then add a new migration file. & make this column nullable.like
Schema::table('your_table_name', function (Blueprint $table) {
$table->string('modified_at')->nullable()->change();
});
For details
https://laravel.com/docs/5.8/migrations#modifying-columns
you are not passing the value to 'modified_at' column when inserting the data so the error is thrown.
You should either make that column have a default value or seeing the column name I guess making it nullable will do.
(Assuming the column is a date field and using Laravel)
You will have to use Column modifier ->nullable()
Migration:
$table->date('modified_at')->nullable();
.
We are using Magento 1.9 for our application. Here is my sample code
$customer_collection= Mage::getModel("customer/customer")->load($data['customer_id']);
foreach ($data['data'] as $key => $customer) {
$customer_collection->setData($customer['attribute_name'] , $customer['attribute_value']);
}
$customer_collection->save(); //finally saving the data
Above code is working for all the fields except date field. Issue is when we send multiple data including date fields, other fields are getting updated but date field is not getting updated. Can anyone help me to solve this issue?
For date field update try to use
$object->setData($attributeCode, Varien_Date::now());
As #mladen-ilić Suggested,
I did Flush Cache Storage and tried again to post the data. It works like a charm.
I'm using MySQL to store my data using PHP. In my table, I have two fields as date (Start_date and End_date). I'm having issue on those fields while saving the data. I gave the input as following
start_date: 2016-12-03 it saved as ---> 2192-12-03
I don't now what is the issue please anyone help in that.
sample code for inserting in cake php 3
$add_val= $this->school->newEntity();
$save_val= $this->school->patchEntity($add_val, $this->request->data);
if ($save = $this->school->save( $save_val))
{
$passmessage = ['status' => 'success];
}
school is the table name.
I need to retrieve the birthday of a student from the database and set it as the birthday of a student entity. Then I need to load that data to a form.
$birth_day = strtotime($student_[0]['birthday']);
$birth__day = date('Y-m-d H:i:s',$birth_day);
$student->setBirthday($birth__day);
And in the form builder I have used the below code
add('birthday', 'birthday',array(
'data' => new \DateTime(),'placeholder'=>'-SELECT-'))
Instead of the birthday that particular student, it shows the today's date.
Can someone please explain what should I do to load the birthday instead of the today's date.
Thankyou in advance.
When you use the 'data' option, you are setting the default value for the field so in your example you are setting it to a new Datetime (today).
Here is the symfony doc page about it http://symfony.com/doc/current/reference/forms/types/form.html#data
Like #abdiel suggested, remove the data part.
I have a problem with a symfony form and a date field. When I view the field, the value retrieved from the database is subtracted a day when it is rendered as a widget single_text and I can not fix it.
For the project I use Symfony 2.6Beta for Bootstrap form support.
The field in form is defined:
$builder->add('natoIl', 'birthday', array(
'widget' => 'single_text',
'empty_value' => '',
'format' => 'dd/MM/yyyy',
'model_timezone' => 'Europe/Rome',
'view_timezone' => 'Europe/Rome'
));
I have this problem with MySQL and PostgreSQL.
Thank you very much
EDIT:
The problem occurs only with the 'widget' option set to "single_text". I need to see it as text input to add a datepicker field.
EDIT #2:
Doing various tests I found that the problem is when I work with the PHP web server. PHP version I use is 5.5.9-1ubuntu4.5 PC with linux mint.
Possibly you need to set your view and/or model timezone appropriately:
http://symfony.com/doc/current/reference/forms/types/date.html#view-timezone
This is a bug already fixed. The solution is then upgrading symfony.
https://github.com/symfony/symfony/issues/12808