Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Poor_RJ's avatar

Time Format issue in ubuntu server with Laravel 10

Hi, I am hosting Laravel 10 project on Ubuntu server. It has a report. But current time in database is not given correctly in ubuntu server. Help me to get correct time format in ubuntu server.

Database created_at :2023-07-31 08:18:19 Ubuntu server report view :"2023-07-31T02:48:19.000000Z"

Product Controller :

public function report(Request $request) { $searchOptions = $request->get('search', null); $searchKeyword = $searchOptions['value'] ?? null;

    $FromDate = $request->get('from_date', null);
    $ToDate = $request->get('to_date', null);

    $query = Product::query()
        ->leftJoin('users', 'users.id', '=', 'products.user_id')
        ->selectRaw('products.*, users.name')
        ->when((!is_null($FromDate) && !is_null($ToDate)), function ($q) use ($FromDate, $ToDate) {
            $ToDate = Carbon::parse($ToDate)->addDays(1);
            $q->whereBetween('products.created_at', [$FromDate, $ToDate]);
        })
        ->when($searchKeyword !== '', function ($q) use ($searchKeyword) {
            $q->where('users.name', 'LIKE', '%'.$searchKeyword.'%')
                ->orWhere('products.workorder', $searchKeyword);
        });
    $total = $query->count();
    $product = $query->simplePaginate($total);
    if ($request->expectsJson()) {
        return response()->json($product);
    }
    return view('products.report', compact('product'));
}

How to fix it??????????????

0 likes
5 replies
tschope's avatar

What happened it's the Ubuntu server handled with UTC, or 0 GMT, hour and you are in a different timezone.

I recommend you check the installation of your database if they are following the Ubuntu installation or using UTC, I recommend you use UTC all the time and the config at the Laravel application when you change your timezone.

You will avoid a lot of problems and you can handle with multiple timezones in your application, based on the user properties, for example.

1 like
DhPandya's avatar

@poor_rj As far I know databases of the server uses the default timezone of the Server. All the servers have UTC as a default timezone and the timezone you provided is also from the UTC. 2023-07-31T02:48:19.000000Z

jlrdw's avatar

Store UTC but convert to local for display or usage. Each users timezone should be stored somewhere perhaps in their profile.

Please or to participate in this conversation.