[英]How to get Date & Time from Database table column in laravel?
I'm trying to store and get current date & time from Database.我正在尝试从数据库中存储和获取当前日期和时间。 I'm trying this
我正在尝试这个
$current_time = Carbon::now();
'order_date_and_time' => $current_time,
'delevery_date_and_time' => $current_time->addDays(3),
Here is my migration这是我的迁移
$table->dateTime('order_date_and_time');
$table->dateTime('delevery_date_and_time');
I store current date & time perfectly but I couldn't get date & time.我完美地存储了当前日期和时间,但我无法获得日期和时间。 I use this method to get DateTime
我用这个方法来获取 DateTime
toDateTimeString()
I got this error我收到了这个错误
"Call to a member function toDateTimeString() on string"
Can anyone tell me how can I get Date & Time?谁能告诉我如何获得日期和时间?
Add order_date_and_time
and delevery_date_and_time
to $dates
in your model.在 model 中将
order_date_and_time
和delevery_date_and_time
添加到$dates
。 It will cast the attributes to Carbon instance as said in laravel doc它将属性转换为 Carbon 实例,如laravel 文档中所述
protected $dates=[
'order_date_and_time',
'delevery_date_and_time',
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.