FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » [newbie] datetime issues
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
[newbie] datetime issues [message #174369] Wed, 08 June 2011 22:54 Go to next message
Jeff[1] is currently offline  Jeff[1]
Messages: 2
Registered: June 2011
Karma: 0
Junior Member
hi

php 5

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:
convert('2012-'.date('m').'-01 00:00:00',DATETIME)
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 [message #174370 is a reply to message #174369] Thu, 09 June 2011 00:12 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 6/8/2011 6:54 PM, Jeff wrote:
> hi
>
> php 5
>
> 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:
> convert('2012-'.date('m').'-01 00:00:00',DATETIME)
> 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

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
would be

$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'

--
Shelly
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: self-modifying program
Next Topic: me? pl's visit
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Dec 04 08:48:30 GMT 2024

Total time taken to generate the page: 0.02363 seconds