Date Nightmare

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kimgreenop
Forum Newbie
Posts: 1
Joined: Sun Oct 25, 2009 9:16 am

Date Nightmare

Post by kimgreenop »

Hi all,

I'm having a date format nightmare.

I have a database with a timestamp.

Now all i want to do is pull up the information for the current month.

Code: Select all

 
//To get the current date
$date1 = getdate(date("U"));
$date1 = $date1[month];
 
$details = mysql_query("SELECT  
                user.id AS usid,
                user.username,
                COUNT(comment.userid) AS userid,
                date('F', comment.date) AS dates
            FROM    comment
            WHERE   dates = $date1
            JOIN    user ON user.id = comment.userid
            GROUP BY userid
 
I feel like I'm going completely the wrong and difficult path.

Any help please.
x
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Date Nightmare

Post by superdezign »

getdate() takes a timestamp. date() does not return a timestamp. time() does, and is already the default parameter of getdate(). So, just typing "getdate()" will get you an array of date information for the current date.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Date Nightmare

Post by requinix »

superdezign wrote:date() does not return a timestamp.
It does when you give it a "U".

Code: Select all

SELECT 
    user.id AS usid,
    user.username,
    COUNT(comment.userid) AS userid,
    date('F', comment.date) AS dates
While MySQL does have a DATE() function, that's neither how to use it nor what you want to use. DATE_FORMAT is more appropriate.
Post Reply