Do you have a question? Post it now! No Registration Necessary. Now with pictures!
June 8, 2011, 10:54 pm
rate this thread
I'm trying to construct an sql query where I need to filter between 2 dates.
So how do I dynamically create those datetime values?
Tip: The day value will always be 1 (or 01 ?).
I will dynamically select values from the entire last month.
I tryed this:
which gave me syntax error and also I need to some more if testing on year.
So hope there is a better way of doing this
please help me
Re: [newbie] datetime issues
What do you mean by "from the entire last month"? The expression you
have will give for June, for example, '2012-06-01 00:00:00' which is
already in DATETIME format (which I assume is how your data are stored
in that column). So, if you want everything from the first of June it
$sql ="SELECT WHATEVER FROM WHEREVER ";
$sql .= "WHERE THE_COL_NAME >= '2012-" . date('m') . "-01 00:00:00'";
Note that the final value of $sql in this case, for June, would be
SELECT WHATEVER FROM WHEREVER WHERE
THE_COL_NAME >= '2012-06-01 00:00:00'