PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Laravel: whereBetween to accept the first date

 February 20, 2022     eloquent, laravel, laravel-5, php     No comments   

Issue

Scenario:

The startdate and enddata in the database is 2015-07-20 and 2015-07-30 respectively and the query that works properly is,

Model::whereBetween('startdate',array('2015-07-30','2015-08-10'))->get();

The query return 1 record from the table which is the expected result. Now what I expect is a slight change. The query should not retrieve the record by considering the date 2015-07-30 does not fall in between 2015-07-30. How do I achieve this?


Solution

whereBetween is inclusive. In order to exclude one of the edges you'll need to build a between query manually:

Model::where('startdate', '>', '2015-07-30')->where('startdate', '<=', '2015-08-10')->get();


Answered By - jedrzej.kurylo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing