1

I have problem with format date while query get data in laravel.

I want output format date of pubDate is: Tue Aug 08 10:18:15 +0000 2018

$posts = DB::table('posts')
    ->select('link','guid','title',DB::raw('DATE_FORMAT(pubDate, "%W %M %d %H:%i:%s +0000 %Y") as pubDate'),'description')
    ->where('hashtag_id',$hashtag_id)
    ->offset(1)
    ->limit(10)
    ->get();

How can I replace +0000 with format timezone of laravel in query above?

Thanks.

Mike
  • 23,542
  • 14
  • 76
  • 87
  • 1
    Possible duplicate of [How to Convert UTC Date To Local time Zone in MySql Select Query](https://stackoverflow.com/questions/15017799/how-to-convert-utc-date-to-local-time-zone-in-mysql-select-query) – Mike Aug 08 '18 at 03:27
  • See also this answer: https://stackoverflow.com/a/15419843/811240 – Mike Aug 08 '18 at 03:35

1 Answers1

0

Please Try this code

$posts = DB::table('posts') ->select('link','guid','title',DB::raw('DATE_FORMAT(pubDate, "%W %M %d %H:%i:%s %+0000% %Y") as pubDate'),'description') ->where('hashtag_id',$hashtag_id) ->offset(1) ->limit(10) ->get();

%% is A literal % character

Correct one is "%W %M %d %H:%i:%s %+0000% %Y"

Sunny Kalariya
  • 336
  • 2
  • 9