0

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 ?

Teoman Tıngır
  • 2,766
  • 2
  • 21
  • 41

2 Answers2

1

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'
Javi Stolz
  • 4,720
  • 1
  • 30
  • 27
  • but I already changed time format with `protected $dateFormat = "Y-m-d";` it shows time as `y-m-d` format . There is a problem with datatable – Teoman Tıngır Sep 11 '18 at 10:49
1

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.

yash
  • 2,101
  • 2
  • 23
  • 32