php


Date Query with Doctrine


I have fields in my table for date, but they contain everything - day, year and month. Can I write a query to get only the records, which has month equal to the current month? I can do this:
$today = new \DateTime();
$month = $today->format('m');
$cat = $em->getRepository('EMBudgetTrackerBundle:Expense')->find(1);
$ex_date = $cat->getDate();
and compare $month and $ex_date, but can I write some kind of query? Something like this:
public function getExpensesByMonth($month)
{
$q = $this->createQueryBuilder('e');
$q->select('e')
->where('e.date = :date')
->setParameter('date', $month);
return $q->getQuery()->getResult();
}
Thank you in advance! :)
If you database column is in DateTime format you can use the DateTime object in your query. As far as I know you can only query for time ranges though.
public function getExpensesByMonth($beginning, $end)
{
$q = $this->createQueryBuilder('e');
$q->select('e')
->where('e.date > :beginning')
->andWhere('e.date < :end')
->setParameter('beginning', $beginning)
->setParameter('end', $end);
return $q->getQuery()->getResult();
}

Related Links

I cannot figure out why I am getting this MySQL syntax error (PHP PDO) (MySQL)
Adding an option “Select all” to an EntityType Field returns the error “Unable to reverse value for property path”
Table Generator plugin not visible to Author role [WordPress]
sqlite & windows: Not enough storage is available to complete this operation and CoInitialize has not been called
Friendly links with $_GET
Cant retrive cell values in my for loops. Gets stuck in infinit loop
how to get data from a query that return a 3 dimension array and set values on a twig view in symfony 3
PHPExcel conditionally formatting a range with a formula
how to store uploaded one image to parent and sub directories
Check ulr before redirect
CodeIgniter cropping devalue image colors
How to stop unwanted redirect ? (redirect headers are blank , no referrer)
form using action from dropdownlist
Select with 2 count on 3 tables laravel
How to identify and fine tune performance bottleneck on PHP+MySQL app on a dedicated server?
Permutation of ten elements array

Categories

HOME
automapper
functional-programming
stacktrace.js
dafny
openlayers-3
mirc
facebook-android-sdk
angular2-template
eddystone
stack-overflow
hystrix
alljoyn
spring-jpa
amazon-elb
jpa-2.0
vertica
jitsi
ini
jpa-2.1
data-collection
introspection
plyr
sap-lumira
ccavenue
fatfs
plantuml
express-session
stackpanel
nsuserdefaults
aurelia-cli
uivisualeffectview
microsoft-ui-automation
aurelia-http-client
tidal-scheduler
elasticsearch-aggregation
jqgrid-asp.net
oracle-bmcs
code-push
xcode8.2
tinyioc
libreoffice-writer
amazon-elastic-beanstalk
http-basic-authentication
network-protocols
word-2016
degrees
emf-compare
gawk
google-identity-toolkit
cdo.message
fiber
fdt
xcopy
trust
ioctl
in-app-billing
largenumber
asp.net-web-api-helppages
blank-line
gluon-desktop
search-form
compositetype
flow-js
dbmigrate
mathematical-expressions
lifetime
encryption-symmetric
producer
jquery-mobile-flipswitch
senchatouch-2.4
neo4jphp
roxy-fileman
windows-taskbar
spring-security-acl
application-server
mousemotionlistener
.net-remoting
sunstudio
aero
xmlwriter
ckeditor.net
tridion-2011
multiple-dispatch
towers-of-hanoi
onconfigurationchanged
story
image-formats
monocross
uploading
dynamic-c
litespeed
drawimage
datacontracts
uipasteboard
css-friendly
pyjamas
outlook-2007-addin
projectpier
tacit-programming
inversion
autobench
error-detection

Resources

Encrypt Message