admin管理员组文章数量:1122832
Is it possible to save a column as ISO8601 format that is not a string type?
Basically, I want to save the date and time as shown below:
2024-11-21T19:30:00.
I tried to use timestamp, so
$table->timestamp('start');
but it saves the data as 2024-11-21 19:30:00, so not as I want.
Is there a way to save it directly or do I have to use string, so $table->string('start')
?
Is it possible to save a column as ISO8601 format that is not a string type?
Basically, I want to save the date and time as shown below:
2024-11-21T19:30:00.
I tried to use timestamp, so
$table->timestamp('start');
but it saves the data as 2024-11-21 19:30:00, so not as I want.
Is there a way to save it directly or do I have to use string, so $table->string('start')
?
1 Answer
Reset to default 0One way to go about it is to treat it as a string and call the Carbon object to parse it to ISO8601 format when you need it.
本文标签:
版权声明:本文标题:php - How to save into DB a column containing 'ISO8601 strings' as a format in Laravel migration - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308595a1933714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$model->start->toIso8601String()
to display that value while keeping the correct value in the database. – Tim Lewis Commented Nov 21, 2024 at 18:51