Getting Data Posted in Between Two Dates

Getting data posted in between two dates

This looks like what you need:

$this->db->where('order_date >=', $first_date);
$this->db->where('order_date <=', $second_date);
return $this->db->get('orders');

Query to select data between two dates with the format m/d/yyyy

This solution provides CONVERT_IMPLICIT operation for your condition in predicate

SELECT * 
FROM xxx
WHERE CAST(dates AS date) BETWEEN '1/1/2013' and '1/2/2013'

Sample Image

OR

SELECT * 
FROM xxx
WHERE CONVERT(date, dates, 101) BETWEEN '1/1/2013' and '1/2/2013'

Sample Image

Demo on SQLFiddle

SQL query to select dates between two dates

you should put those two dates between single quotes like..

select Date, TotalAllowance from Calculation where EmployeeId = 1
and Date between '2011/02/25' and '2011/02/27'

or can use

select Date, TotalAllowance from Calculation where EmployeeId = 1
and Date >= '2011/02/25' and Date <= '2011/02/27'

keep in mind that the first date is inclusive, but the second is exclusive, as it effectively is '2011/02/27 00:00:00'

.NET - getting the data between two dates

You need to format the dateTimePicker1.Value and dateTimePicker2.Value to strings that sql can read as
a date. ISO format 'yyyy-mm-dd' would be ideal for most sql engines.

in c# you do this...

string fromDateStringISO = Convert.ToDateTime(dateTimePicker1.Value).ToString('o');
string toDateStringISO = Convert.ToDateTime(dateTimePicker2.Value).ToString('o');

string kayit = "SELECT * FROM Kabin_Verileri where Readtime BETWEEN '" + fromDateStringISO + "' and '" + toDateStringISO + "'"

'o' format is ISO format. Check here

How to get list of dates between two dates in mysql select query

Try:

select * from 
(select adddate('1970-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
(select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between '2012-02-10' and '2012-02-15'

-for date ranges up to nearly 300 years in the future.

[Corrected following a suggested edit by UrvishAtSynapse.]



Related Topics



Leave a reply



Submit