0

I have a query which filters through a table for items with a specific insertion date. The date is of timestamp format.

When I used the following comparison in the query, it works fine:

created > DATEADD(DAY,-5, CAST(GETDATE() AS DATE)

But when I parametrize the query as below:

created > :tomorrow

where tomorrow defined as below:

$tomorrow = new \DateTime( 'tomorrow' );
$tomorrow->setTime( 0, 0, 0 );
$tomorrow = $tomorrow->format( 'Y-m-d');

Then it doesn't work. Does it have anything to do with the format of the tomorrow date?

TMA
  • 33
  • 4
  • Well your first query is "if created is more than 5 days ago" but your other query is "if created is bigger than tomorrow". So your queries are *not* the same, not sure what you are trying to achieve – IsThisJavascript Sep 19 '17 at 14:42
  • @WillParky93 it's just an example, what I meant is that when I parametrize it, it doesn't work – TMA Sep 19 '17 at 14:43

2 Answers2

0

This is not timestamp:

$tomorrow = $tomorrow->format( 'Y-m-d');

If you want to compare a timestamp field for "tomorrow" use:

strtotime('tomorrow')
  • Thank you for your reply, when I do $tomorrow = strtotime('tomorrow') it stops. – TMA Sep 19 '17 at 14:45
0

By doing $tomorrow = $tomorrow->format( 'Y-m-d'); you tranform the original date in variable $tommorow to string. If you parametrized the date, no further transformation should be needed.

px1mp
  • 5,212
  • 1
  • 18
  • 10