Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pulling Data From Last Month

    I can't seem to to make the query call out last months highest clicks. I read the INTERVAL and subdate but don't know how to apply it.

    I'm trying to get the last month and not 30 days. Any help would be appreciated.


    SETTING====
    Fieldname: time
    Type: int
    UNIXTIME

    Here's what I have for the query:

    SELECT id, title, url, imgname, clicks
    FROM students
    WHERE approved = 'yes'
    ORDER BY clicks DESC
    LIMIT 8

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can't use date_sub() function on an INT data type. Convert your field to a DATETIME data type and then you can use datetime functions on that field...

    Code:
    SELECT *
    FROM table1
    WHERE month(datefield1) = month(date_sub(datefield1) INTERVAL 1 month)

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    how do you mean by last month and not 30 days. Do you mean February?

    YOu will also have to use FROM_UNIXTIME if you are using a UNIX timestamp.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, sorry, I mean by February. When I changed the INT into DATETIME, it reseted all my dates into 0000-00-00 00:00:00
    Last edited by curb; 03-15-2007 at 12:52 AM.

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need to convert the data, not just change the data type and pray. Guelphdad has a link in his sig how to do this.

  • #6
    New Coder
    Join Date
    May 2006
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whew, I finally got it to work. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •