Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable show time 1 hour behind than what is in db #3215

Open
petethewizard opened this issue Feb 7, 2025 · 1 comment
Open

DataTable show time 1 hour behind than what is in db #3215

petethewizard opened this issue Feb 7, 2025 · 1 comment

Comments

@petethewizard
Copy link

I have a DataTable set up to display "updated_at" from a table and my timezone in app.php is Europe/Berlin but the DataTable always displays the time 1 hour behind than what is stored in the db? Why is that happening? Is there a way to disable it? I assume this has something to do with the automatic detection of date fields. Also, when using editColumn on the datetime field is shows the correct time. However, I trying to find another way to fix this.

I am using version 11.0.0. Laravel 11. PHP 8.2. Any help appreciated!

@yajra
Copy link
Owner

yajra commented Feb 11, 2025

Below is a DateTimeColumn I am using to display the time on the client timezone. Feel free to adjust as needed. Basically, I used moment JS to change the way the data is rendered on the client side.

<?php

declare(strict_types=1);

namespace App\Editor\Columns;

use Yajra\DataTables\Html\Column;

class DateTimeColumn extends Column
{
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $this->render('data ? moment(new Date(data)).format("MM/DD/YYYY hh:mm a"): ""')
            ->exportFormat('mm/dd/yyyy h:mm am/pm')
            ->width('170px');
    }
}

Usage

DateTimeColumn::make('updated_at'),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants