0

Hi I am trying to get dates after datetime('now)

My query is not checking against the time value.

I have the following dates :

  • 2015-09-03 18:00:00
  • 2015-09-03 18:00:00
  • 2015-09-10 16:30:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 09:00:00
  • 2015-09-13 12:05:00
  • 2015-09-13 12:05:00
  • 2015-09-13 12:25:00
  • 2015-09-13 12:25:00
  • 2015-09-13 12:25:00
  • 2015-09-13 16:30:00
  • 2015-09-14 15:10:00
  • 2015-09-14 18:20:00

It seems to ignore the time completely I can get it to return anything after the 14th, i would expect it to return anything where the time is greater than my startdate (2015-09-14 12:40:39)

public function getRemainingKeysForTimeframe($timeframeID){ $startDate = new \DateTime('now'); $queryBuilder = $this->createQueryBuilder('q') ->select('q') ->andWhere('q.timeframeID = :timeframeID') ->andWhere('q.date >= :start') ->setParameter('timeframeID', $timeframeID) ->setParameter('start', $startDate->format('Y-m-d h:i:s')); return $queryBuilder; } 
4
  • 1
    your startdate is (2015-09-14 12:40:39)? seems to me there is no date later than that (they are all set to 2015-08...) Commented Sep 14, 2015 at 13:05
  • I just copied and pasted the range from the db, have updated my question in in clude more references Commented Sep 14, 2015 at 13:18
  • 1
    Have you tried using H instead of h in your format? Commented Sep 14, 2015 at 13:18
  • managed to fix it, i was getting data from a table where the date field was date not dateTime Commented Sep 14, 2015 at 13:27

1 Answer 1

1

Inject the actual \DateTime object as a parameter in your query builder:

->setParameter('start', $startDate); 

not

->setParameter('start', $startDate->format('Y-m-d h:i:s')); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.