First show you the next date format effect chart, if you are satisfied please continue reading:
We'll discuss this in a separate situation.
1, if your database field Created_at save time format is date or datetime, it is very simple, the GridView directly output the field created_at can be, as shown in the figure on the right
2. If the timestamp type of the database is stored, as shown on the left side of the image above, you need to output as follows
[
' attribute ' => ' created_at ', '
value ' => function ($model) {return
date (' y-m-d h:i:s ', $model-> CREATED_AT);
},
],
[
' attribute ' => ' created_at ', '
format ' => [' Date ', ' y-m-d h:i:s '],
],
The above shows two ways to format the output, all can. However, if you want to implement the search mechanism, if your database is in a datetime type, it is very convenient, dataprovider do not have to make changes,
The code is as follows
$query->andfilterwhere ([
//...
] Created_at ' => $this->created_at,
//...
]);
If your database is stored in a timestamp.
The first step is to modify the corresponding rule as shown in the following figure
The second step, modify Dataprovider can refer to the following code
The format we enter in the search input box is generally 2016-01-01 instead of timestamp
/output 2016-01-01 nothing more than to search for this day's data, so the code is as follows
if ($this->created_at) {
$ Createdat = Strtotime ($this->created_at);
$createdAtEnd = $createdAt + 24*3600;
$query->andwhere ("Created_at >= {$createdAt} and Created_at <= {$createdAtEnd}");
Here to make a small summary, suggest using datetime type, personal feel the time stamp is troublesome, if you have good suggestions, welcome to my message, learn and progress together. Here also thank you very much for the cloud Habitat Community website support!