1

I am trying to convert the timestamp to date format by using from_unixtime(timestamp_utc) but i couldn't be successfull, can you help me please!!

public function kamp_yon_ozt_rek_tracker() {
    $id=Auth::user()->id;
    $all=DB::table('kampanya_yonetimi')
           ->join('reklam_yukleme','kampanya_yonetimi.reklam_yukleme_id','=','reklam_yukleme.id')
           ->join('kampanya_ozeti','kampanya_yonetimi.kampanya_ozeti_id','=','kampanya_ozeti.id')
           ->join('tracker_results','kampanya_yonetimi.file','=','tracker_results.title')
        ->where('kampanya_yonetimi.user_id','=',$id)
        ->whereBetween('from_unixtime(tracker_results.timestamp_utc)', ['2019-01-01 11:59:57', now()->addDays
        (0)])
            ->orderBy('from_unixtime(tracker_results.timestamp_utc)')
            ->get()
            ->groupBy(function ($val) {
                return Carbon::parse($val->timestamp_utc);
                //->format('Y/m/d');
            });

    return $all;
}

Unknown column 'from_unixtime(tracker_results.timestamp_utc)

1 Answer 1

1

By default eloquent/DB query builder will apply back quote() enclosed to whatever inside it. For this problem, You can useDB::raw` here to consider it as is,

->orderBy(DB::raw('FROM_UNIXTIME(tracker_results.timestamp_utc)'))

Change your line with mine. It should work.

Note: I suggest you should use capital cases for core MySQL functions for better readability and standards i.e. FROM_UNIXTIME.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks sir, also i have used ; ->whereBetween(DB::raw('FROM_UNIXTIME(tracker_results.timestamp_utc)') , then i have fixed the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.