您好,登錄后才能下訂單哦!
Laravel 的查詢構建器支持 PostgreSQL 的日期和時間函數。以下是一些常用的日期和時間函數及其在 Laravel 中的用法:
use Illuminate\Support\Facades\DB;
$currentDateTime = DB::table('your_table_name')->select(DB::raw('CURRENT_TIMESTAMP'))->first();
use Illuminate\Support\Facades\DB;
$date = DB::table('your_table_name')->select(DB::raw('date_part(\'day\', your_date_column) as day'))->first();
use Illuminate\Support\Facades\DB;
$date = DB::table('your_table_name')->select(DB::raw("to_char(your_date_column, 'DD') as day"))->first();
use Illuminate\Support\Facades\DB;
$hour = DB::table('your_table_name')->select(DB::raw('date_part(\'hour\', your_date_column) as hour'))->first();
use Illuminate\Support\Facades\DB;
$minute = DB::table('your_table_name')->select(DB::raw('date_part(\'minute\', your_date_column) as minute'))->first();
use Illuminate\Support\Facades\DB;
$second = DB::table('your_table_name')->select(DB::raw('date_part(\'second\', your_date_column) as second'))->first();
use Illuminate\Support\Facades\DB;
$newDate = DB::table('your_table_name')
->where('id', 1)
->update([
'your_date_column' => DB::raw('your_date_column + INTERVAL \'1 day\'')
]);
use Illuminate\Support\Facades\DB;
$newDate = DB::table('your_table_name')
->where('id', 1)
->update([
'your_date_column' => DB::raw('your_date_column - INTERVAL \'1 day\'')
]);
use Illuminate\Support\Facades\DB;
$formattedDate = DB::table('your_table_name')
->select(DB::raw("to_char(your_date_column, 'YYYY-MM-DD HH24:MI:SS') as formatted_date"))
->first();
請注意,這些示例假設您已經連接到了 PostgreSQL 數據庫。如果您的數據庫連接設置不同,請確保在 config/database.php
文件中正確配置您的連接信息。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。