Formatting a date column in table builder
Created 6 years ago by william

In my tablebuilder, i have a custom query for my view ( see below ). I would like to format that date to only display year and month. What is the best way?

protected $views = [
    'future' => [
        'query'   => FutureQuery::class,
        'text'    => 'Future Events',
        'columns' => [
            'title',
            'date'

        ],
    ],
    'past' => [
        'query'   => PastQuery::class,
        'text'    => 'Past Events',
        'columns' => [
            'title',
            'date'

        ],
    ],
    'all'
];
william  —  6 years ago Best Answer

Answer

protected $views = [
    'future' => [
        'query'   => FutureQuery::class,
        'text'    => 'Future Events',
        'columns' => [
            'title',
            'date' => [
                'value' => "entry.date.format('M Y')",
            ],

        ],
    ],
    'past'   => [
        'query'   => PastQuery::class,
        'text'    => 'Past Events',
        'columns' => [
            'title',
            'date' => [
                'value' => "entry.date.format('M Y')",
            ],

        ],
    ],
    'all',
];