+ Reply to Thread
Results 1 to 7 of 7

Thread: MySQL Functions

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    MySQL Functions

    I have been trying to figure out how to select the following from my database.

    Select information between beginning of this week and now()

    "SELECT * FROM database WHERE ____ "

    Is this correct for selecting all content from the beginning of the month to now

    SELECT * FROM database WHERE DATEDIFF(NOW(), date) > 0 AND DATEDIFF(NOW(),DATE_FORMAT(NOW(), '%Y-%m-01')<0) LIMIT 1

    Any help is greatly appreciated

  2. #2
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: MySQL Functions

    just to be sure, database is a table in the database itself?

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: MySQL Functions

    Quick thoughts...

    Assuming date is a legit date, also not in future....

    For this month (assuming you mean calendar month and not 30 days ago...)

    Code:
    SELECT * FROM tablename WHERE  MONTH(NOW()) = MONTH( date ) 
               AND YEAR( NOW() ) = YEAR( date )
    For this week (assuming you mean calendar week and not 7 days ago...)

    Code:
    SELECT * FROM tablename WHERE  WEEK(NOW()) = WEEK( date ) 
               AND YEAR( NOW() ) = YEAR( date )
    
    as a start. This does fail over New Years, but you could add an OR phrase to cover that.

    mySQL WEEK function has a second arguement where you can set whether your week starts on Sunday or Monday.

    You might also look into the YEARWEEK function that might fix the New Years problem with WEEK
    Last edited by descalzo; 10-24-2009 at 06:42 PM.
    Nothing is always absolutely so.

  4. #4
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: MySQL Functions

    Thanks again to the all knowing descalzo.

    I used your method for month but i did look into YEARWEEK() and decided to go with that.

    Thanks again for the help.

  5. #5
    yellow202 is offline x10Hosting Member yellow202 is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    7

    Re: MySQL Functions

    test

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL Functions

    Quote Originally Posted by yellow202 View Post
    test
    Don't post off-topic to a thread; it's bad netiquette. Start a new thread in the appropriate forum, which is off-topic if there's no other forum.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    playminigames is offline x10 Sophmore playminigames is an unknown quantity at this point
    Join Date
    Jul 2009
    Location
    earth
    Posts
    216

    Re: MySQL Functions

    you might of had a problem with the LIMIT 1 function, because it limits the result to one, so you wont get all the results.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Which is better postgresql or MySQL?
    By Kurai Kumo in forum Scripts & 3rd Party Apps
    Replies: 11
    Last Post: 12-10-2009, 08:17 AM
  3. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  4. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers