I have sql-server column called (date) with int type and the value for this column is timestamp like (1538254800) i need to select this column from my laravel sql query and appear it as date format (Y-m-d H:m:i pm) like (2018-09-29 09:00:00 pm)
Asked
Active
Viewed 196 times
-2
-
3That is [EPOCH](https://stackoverflow.com/questions/4787827/converting-epoch-timestamp-to-sql-serverhuman-readable-format)... then you can use `CONVERT` to get it in the format you want. – S3S Mar 29 '19 at 19:48
-
`date(FORMAT, $string)` doesn't do it? or you want it done in SQL? – user3783243 Mar 29 '19 at 19:53
-
select CONVERT(datetime, convert(varchar(10), 20190329)); – CR241 Mar 29 '19 at 20:07
1 Answers
0
Casts
https://laravel.com/docs/5.8/eloquent-mutators#attribute-casting
Example:
class MyModel extends Model {
// ...
protected $casts = [
'int_col_name' => 'datetime:u',
];
// ...
}
Date mutators
https://laravel.com/docs/5.8/eloquent-mutators#date-mutators
Example:
class MyModel extends Model {
// ...
protected $dates = [
'int_col_name',
];
// ...
}

Mgorunuch
- 647
- 1
- 5
- 16