symfony2 how to create query builder between two dates with startdate enddate included - query-builder

How to create query builder between two dates (startdate enddate) with startDate endDate included.
SQL example : Select * from fiche.f
WHERER ((f.creationdate >= satrtDate)
AND (f.creationdate <= endDate))

In PostgreSQL, I would use BETWEEN $date1 and $date2 and it seems to work in Doctrine too.
$queryBuilder->where('f.creationdate BETWEEN f.startDate and f.endDate')

You can use $startdate = date('Y-m-d', strtotime($start. ' - 1 days')) and $enddate = date('Y-m-d', strtotime($end. ' + 1 days'))

Related

How to add DATE_ADD in query on laravel

I have such a query
SELECT DATE_ADD(do, INTERVAL 1 DAY) AS od from termin
and I want to convert them to query in Eloquent
$tab = DB::table('termin')->get
how to do it
Thank you for your help
You can convert your query as like below.
$tab = DB::table('termin')->selectRaw('DATE_ADD(do, INTERVAL 1 DAY) AS od')->get();

How can i show single data in view if today date is in between start date & end date in laravel?

I have Admission table which have id, school_id, start_date,end_date etc and i want to show single data if today's date is between start_date & end_Date in laravel eloquent
Applying below code you can get the latest data of current date
$currentDate = date('Y-m-d');
$result = my_table::where(DB::raw('DATE(start_date)'), '<=' , $currentDate)
->where(DB::raw('DATE(end_Date)'), '>' , $currentDate)
->orderBy('id','desc')
->first();
`$start_date = date('2018-01-01');
$end_date = date('2018-05-02');
Adminssion::whereBetween(Carbon\Carbon::now()->toDateString(), [$start_date, $end_date])->get();`
The carbon now() function will give you current date and time. And toDateString() function only give you today date. And with whereBetween() function you can compare the current date between start_date and end_date.

Spring Boot data-jpa and nativeQuery Postgres cast

I have a custom #Query in a repository that looks like this:
SELECT * FROM topicaudit_c14001
WHERE auditdate >= NOW()
AND auditdate <= NOW() + '1 hour'::INTERVAL
AND accepted_status = 'ACCEPTED'
AND reminder_sent = FALSE
When I run this, I get the exception:
org.hibernate.QueryException:
Not all named parameters have been set: [:INTERVAL]
Obviously it is interpreting the ::INTERVAL cast (Postgresql) as a named parameter and cannot fire the query since I don't provide a parameter.
How can I write this query so that it works with JPA?
I found it out shortly after posting. Escaping the :: helps.
SELECT * FROM topicaudit_c14001
WHERE auditdate >= NOW()
AND auditdate <= NOW() + '1 hour'\\:\\:INTERVAL
AND accepted_status = 'ACCEPTED'
AND reminder_sent = FALSE

Get all records between two dates

How can i fetch all records between two date field dates in mysql table.Am using code igniter for my application.
Am entering start date and end date from date picker , need to fetch all rowas >= startdate and <= end date
my code:-
$this->db->where('start_date <= ',$start_date);
$this->db->where('end_date >= ',$end_date);
My query :- SELECT * FROM table WHERE start_date <= '2016-04-13' AND end_date >= '2016-04-19'
This is fetching only one row from table.
Please help
U need to do something like this...
$this->db->select("DATE_FORMAT(date, '%m/%d/%Y') as Urdate",FALSE);
$this->db->from('table');
$this->db->where("DATE_FORMAT(date,'%Y-%m-%d') > '2013-01-01'",NULL,FALSE);
Try this one:
$this->db->where('start_date >= ',$start_date);
$this->db->where('end_date <= ',$end_date);
$this->db->select('*');
$this->db->from('manual_discount');
$this->db->where("DATE_FORMAT(created_datetime,'%Y-%m-%d') >= '2018-09-06'",NULL,FALSE);
$this->db->where("DATE_FORMAT(created_datetime,'%Y-%m-%d') <= '2018-09-06'",NULL,FALSE);
this works fine for me
To solve the above issue you should following below query.
$this->db->select('*');
$this->db->from('table');
$this->db->group_start();
$this->db->where('start_date <=',$start_date);
$this->db->where('end_date >=',$start_date);
$this->db->group_end();
$this->db->group_start();
$this->db->where('start_date <=',$end_date);
$this->db->where('end_date >=',$end_date);
$this->db->group_end();

Cx_oracle: To_date with variables in python

I am trying to do this
startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from bug where submitted_date >= TO_DATE(:1,'dd-MON-yy') and submitted_date <= TO_DATE(:2,'dd-MON-yy')"
cursor.execute(cmd,(startdate,enddate))
I get an error
cursor.execute(cmd,(sdate,edate))
cx_Oracle.DatabaseError: ORA-01861: literal does not match format string
I saw previous threads regarding this error but nothing solved my problem
I am not sure how startdate and enddate is translated to :1 and :2 but if it does, then the issue with date format.
You are passing YYYYMMDD and you casting it as DD-MON-YYYY . Try to change it.
Also you are missing from clause.
And I'd used between clause instead.
select identification_number
from <your_table>
where
submitted_date between
TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')
If this works, then use same date format in your code
startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from <your_table> where submitted_date between TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')"

Resources