1

I was trying to get some records of a table, which has a column 'UpdateDate' with default value NULL. I need to check if a record exists that either 'UpdateDate' is not today or 'UpdateDate' is NULL. The query I built is as follows:

DB::table('Users')
->where('id', '=', '10')
->where(function($query) {  
    $query->where('UpdateDate','<>',date("Y-m-d"))->orWhere('UpdateDate','is','NULL'); })
->exists()

It didn't work as expected. How should I modify it? Thanks.

1 Answer 1

8

Change you query to this

DB::table('Users')
->where('id', '=', '10')
->where(function($query) {  
    $query->where('UpdateDate','<>', date("Y-m-d"))
    ->orWhereNull('UpdateDate'); 
})
->exists();

If you have UpdateDate date as datatype.

If you have timestamp or datetime as datatype then change to this

DB::table('Users')
->where('id', '=', '10')
->where(function($query) {  
    $query->whereBetween('UpdateDate',[date("Y-m-d 00:00:00"), date("Y-m-d 23:59:59")])
    ->orWhereNull('UpdateDate'); 
})
->exists();
Sign up to request clarification or add additional context in comments.

Comments

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.