I can't see any difference if I set this variable or not.
I need some basic example
if this variable is set:
protected $dateFormat = "d.m.Y H:i";
What difference does it make???
P.S. I have already read about in Docu but it's not clear where is this date format actually used??
https://laravel.com/docs/5.5/eloquent-mutators#date-mutators
Update
Using jQuery datetimepicker localized so the date that gets saved is in this format: "25.09.2017 08:04"
changed the column data type in migration from timestamp to dateTime.
changed timezone in config/app.php to: 'timezone' => 'Europe/Berlin',
set the variable to:
protected $dateFormat = "d.m.Y H:i";
And I get an error on form submit:
and if I the variable is NOT set
I get this error:
TL;DR: Your $dateFormat is used to both parse incoming post data, and format data sent to your database. This means that, without any other code (read: setter that overrides this), your UI must use the same datetime format as your database.
The $dateFormat is used by HasAttributes::asDateTime to parse incoming strings into Carbon objects. This method is used in many places to handle automatic casting of the attributes into proper data types. This includes both the $casts array and the $dates array.
One common invocation is via Model::fill(...) > HasAttributes::setAttribute(...) > HasAttributes::fromDateTime(...). Note that Model::__set(...) also calls into HasAttributes::setAttribute(...). This means that the $dateFormat is used to parse incoming string values from [presumed] form posts when you use mass-assignment/fillable, or when you set attributes directly using $model->myField = ...;. You're expected to set the format to what the browsers are posting so the values can be properly parsed into Carbon objects.
The Carbon objects are then serialised back into strings in HasAttributes::fromDateTime(...) which means that Laravel handles your datetime values as strings, which surprised me when researching this. This means that your $attributes array contains string representation of your datetime values, and these string values are sent to the database.
This means that $dateFormat needs to produce a string value supported by your database.
Keep in mind that this is the format of the datetime value when submitted, not shown. The datetime-local html5 datatype, for example, will use the local locale when formatting the datetime, but will always post the value in a specified format.
One thing to note is that the displayed date format differs from the actual value — the displayed date format will be chosen based on the set locale of the user's operating system, whereas the date value is always formatted yyyy-MM-ddThh:mm.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local
That is the format how it is saved in the database.
Related
I am using the NiFi ListAzureBlobStorage to get the available blob objects. The processor creates a flowfile for each object with the attributes containing the object metadata. I want to filter on the azure.timestamp attribute, but I do not know what the numeric value represents and how it relates to the NiFi's expression language date data type. I want to compare it with a known date so I need to convert it to a NiFi data-time variable first. How do I do this?
Thanks
According to the code it is already in "NiFi format" which means a Unix timestamp.
Since it represents the number of milliseconds passed since 1/1/1970, you can compare this and the other timestamp using regular number comparison operators.
example: ${azure.timestamp:ge(${now()})} - this will return true if the azure.timestamp is later(or equal) than the current timestamp(now).
If you'd like to compare it to another attribute you can do this:
${azure.timestamp:ge(${attribute.name})}.
If you'd like to convert a different date into a unix timestamp, you can use toDate and then toNumber, or to do the other way around, just use format.
I'm trying to get release date field with y-m-d format.. Actually time format (for y-m-d) seems fine but also it gives h:m:s too, I changed time format at server side and removed h:m:s but datatable still shows them
What I get
2012-04-11 00:00:00
What I want
2012-04-11
Released_at field (Metronic theme - json datatable)
{
field: "released_at",
title: "Release Date",
type: "date",
format: "YYYY/MM/DD"
}
time format (I'm using laravel framework)
protected $dateFormat = "Y-m-d";
How do I fix this ?
Datatable accept column type same as mysql type.
You are trying to convert mysql dateTime column to Date in datatable, which is not possible from datatable.
In your code you have declared
format: "YYYY/MM/DD" // but actual type is dateTime as per mysql.So it will append time next to it.
If you are storing only date in mysql then you can change column type to Date, and your problem gets solved.
And if you want to convert string to date in laravel you can follow this post.
Your database column is of type dateTime which, by definition, includes both date and time information. If you want to remove the time at a database level then use the date type instead
$table->date("released_at")->nullable();
If instead of removing the time from the database, you just want to ignore it for certain parts of your application, you can leverage the fact than in Laravel all dates coming from your models are Carbon\Carbon instances, so you could do
$model->releasedAt->format('y-m-d'); // Returns '18-09-11'
i tried this in form load event :
DTPicker1.Format = dtpCustom
DTPicker1.CustomFormat = "yyyy/MM/dd"
That didnt work.
when i saved it to my database, it turned into dd/mm/yyyy.
I tested it with a textbox, i sent the value to a textbox, it gave me the same dd/mm/yyyy.
Is there any way to do this?
The standard format of Date field type in databases is normally:
MM/DD/YYYY HH:NN:SS
(Unless expressly indicated, where database allows to set a different format); this is depend from database type.
I.e. Access doesn't allows to store date on other formats.
You must set the custom format after load data using Format() function:
Text1.Text = Format$(YourRecordset!YourData, "yyyy/MM/dd")
I was wondering what would be the easiest way to change in laravel to save timestamps in database as unix valid timestamp?
Thanks in advance!
Please read about Laravel date mutators:
https://laravel.com/docs/5.1/eloquent-mutators#date-mutators
By default, timestamps are formatted as 'Y-m-d H:i:s'. If you need to
customize the timestamp format, set the $dateFormat property on your
model. This property determines how date attributes are stored in the
database, as well as their format when the model is serialized to an
array or JSON
Also, you can override getDateFormat():
protected function getDateFormat()
{
return 'U';
}
And use this in your migration files:
$table->integer('updated_at');
$table->integer('created_at');
And, if you use soft deletes:
$table->integer('deleted_at');
https://laravel.com/docs/4.2/eloquent#timestamps
HI I have a problem in my current Spring +JPA project. My entity object and bean object for web page are same.
From web page using jquery i am reading date in (dd-mon-yyyy) format from screen and saving it to database. The field is of Date type in my bean class.
During update i am fetching values from database and displaying the same in web page. But this time the date format has chnaged to different fromat(yyyy/mm/dd) on screen.
So while saving again i am getting error, as the date format has been changed and i am unable to parse the value received form screen.
So is there any proper way to handle this situation.
I assume that you are storing the dates in database as a DATE or DATETIME type. If so, the value should be a Date object in Java. In order to output the date value as dd-mon-yyyy, you will need to use SimpleDateFormat to convert the date object into a string representation in your desired format:
new SimpleDateFormat("dd-MMM-yyyy").format(date);
An additional note: for an internal-only API, it doesn't matter what format you choose as long as you are consistent everywhere. But if you are creating something that could one day be exposed publicly, I would suggest that you send/receive date and time value in the ISO8601 format: yyyy-MM-ddTHH:mm:ssZ. This format is understood by everyone everywhere.
Update:
Based on your comment, I would say add a new method to your bean class:
private DateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
public String getFromDateString() {
return dateformat.format(fromDate);
}
And then in your JSP, call ${bean.fromDateString}.