-1

Database stored date

item 1: date from :- 10-07-2017 date to :- 20-07-2017
item 2: date from :- 02-07-2017 date to :- 02-08-2017
item 3: date from :- 01-06-2017 date to :- 20-08-2017

input date

start date:- 05-07-2017 end date :- 25-07-2017

here I gave an input date to get data from database. database stored date is the data I want to print. thing is that, which are the items date included in the input date

condition this are the condition I want to work

start_date < date from && end_date > date_to 
start_date > date from && end_date > date_to 
start_date < date from && end_date < date_to 
start_date > date from && end_date < date_to 

exception case

start_date < end_date < date_to
start_date > end_date > date_to

I want a codeignitor solution . below am giving my model class structure

public function getDate( $start_date = "",$end_date = """)
{
$this->db->select('*');
$this->db->from('user_details');
$this->db->where('');
}

table data database image

RAHEEZ PC
  • 21
  • 1
  • 7
  • And you tried what? – bksi Aug 05 '17 at 10:17
  • 2
    Store dates as dates – Strawberry Aug 05 '17 at 10:17
  • Just want to get data from database.I have some user details i gave some privilege to them based on the date duration so I am searching two date to get who all are the users are active in between the date. suppose start date is less than input start date , end date is greater than the start date so that user i want to be selected .. and conditions are given in the question – RAHEEZ PC Aug 05 '17 at 10:32
  • Probably the best way to solve your problem is here [Comparing date ranges](https://stackoverflow.com/a/143568/5077564) – always-a-learner Aug 05 '17 at 11:57
  • thank you ankit suthar its working ..... – RAHEEZ PC Aug 07 '17 at 09:47

2 Answers2

0

Try this line:

$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');

or try like that

$this->db->select('*');
$this->db->from('');
$this->db->where('start_Date <','2012-10-03');
$this->db->where('end_Date >','2012-10-01');

$result = $this->db->get(); 
Anand Pandey
  • 2,025
  • 3
  • 20
  • 39
  • what is sell_date? – RAHEEZ PC Aug 05 '17 at 10:11
  • its a column name for example – Anand Pandey Aug 05 '17 at 10:11
  • but i have multiple column . start_Date and end_date – RAHEEZ PC Aug 05 '17 at 10:13
  • give your full query what you want ? – Anand Pandey Aug 05 '17 at 10:17
  • Just want to get data from database.I have some user details i gave some privilege to them based on the date duration so I am searching two date to get who all are the users are active in between the date. suppose start date is less than input start date , end date is greater than the start date so that user i want to be selected .. and conditions are given in the question – RAHEEZ PC Aug 05 '17 at 10:27
  • start_date < end_date < date_to start_date > end_date > date_to except these two condition that i want to be worked – RAHEEZ PC Aug 05 '17 at 10:30
  • can you provide table structure? – Anand Pandey Aug 05 '17 at 10:36
  • CREATE TABLE `64_user_details` ( `id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `name` varchar(99) NOT NULL, `email` varchar(255) NOT NULL, `profile_pic` varchar(255) NOT NULL, `address` text NOT NULL, `latitude` double NOT NULL, `longitude` double NOT NULL, `start_date` datetime NOT NULL, `end_date` datetime NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; – RAHEEZ PC Aug 05 '17 at 10:38
  • You have to run different queries for different purpose. – Anand Pandey Aug 05 '17 at 10:43
  • Its not possible in only in one query, not get the right result(i think). – Anand Pandey Aug 05 '17 at 10:46
0

use date between(...) or date>date1 and date

Sherif Eldeeb
  • 199
  • 2
  • 11