Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Objects of type "date" in SQL

  • 02-03-2005 4:27pm
    #1
    Closed Accounts Posts: 680 ✭✭✭


    I've looked around the internet for an answer to this, and i can't seem to come up with anything satisfactory. I have a php/sql application, which adds information to a database. One of these bits of information is dates, which i have use the "date" type for the values in the database(as opposed to varchar, or int), and are entered in the format YYYY-MM-DD. Now, what i want to do is retrieve all the values for a particular month, or year. Does anybody know how to do this? At the moment i can only find exact dates, but i need to be less specific. I assume it'd be something like this

    "select from database name, venue where date = ****-11-**";

    Anybody know how to do it?


Comments

  • Registered Users, Registered Users 2 Posts: 119 ✭✭Mike_Hunt


    all you have to do in SQL is

    select * from table where month(date) = x

    substitute x for the month number (as in 1=jan, 12=dec)
    table for your tablename and date for your date field

    and bob should theoretically be your uncle :)


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    Amaru wrote:
    I've looked around the internet for an answer to this, and i can't seem to come up with anything satisfactory. I have a php/sql application, which adds information to a database. One of these bits of information is dates, which i have use the "date" type for the values in the database(as opposed to varchar, or int), and are entered in the format YYYY-MM-DD. Now, what i want to do is retrieve all the values for a particular month, or year. Does anybody know how to do this? At the moment i can only find exact dates, but i need to be less specific. I assume it'd be something like this

    "select from database name, venue where date = ****-11-**";

    Anybody know how to do it?

    For selecting by month use

    where MONTH([date]) = 3

    (for March)

    For selecting by year use

    where YEAR([date]) = 2003


  • Closed Accounts Posts: 680 ✭✭✭Amaru


    So thats what the exact phrase will be, seen as my variable is called "date"?

    And if i was to combine the phrases, it'd be

    WHERE month([date]) = 3 AND year([date]) = 2005?


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    Amaru wrote:
    So thats what the exact phrase will be, seen as my variable is called "date"?

    And if i was to combine the phrases, it'd be

    WHERE month([date]) = 3 AND year([date]) = 2005?

    You'd get dates in March 2005


  • Closed Accounts Posts: 680 ✭✭✭Amaru


    Thats all i needed to know!

    Cheers guys!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    avoid using variables or columns names that are reserved keywords or like reservered key words e.g Date
    something like EnteredDate,
    ProcessedData etc would be better


Advertisement