Mysql date problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kyandebishop
    New Member
    • Sep 2007
    • 4

    #1

    Mysql date problem

    Hello everybody.
    I took database course two years ago and I am having a serious problem.
    I created a table called pet with mySQL 5.0 and it has 6 fields. Among them are two fields for birth Date and death Date.
    When inserting the data I have one pet born today. I am trying to query the pet who was born today but it is not working. Here is my syntex
    [code=mysql]
    SELECT *
    FROM pet
    WHERE birth Date = CURRENT_DATE( ) ;
    [/code]
    I get a syntex error even when I use the CURDATE() function.

    WHAT AM I DOING?
    If this query works. I want to create a TABLE month with date field and message field. Then query it in such a way that each day the message automatically be displayed on our web site as a daily devotional. I do not know if it will work or not.
    If there is anybody out there who can help me with the query above and may be another alternative of my goal please helo me.
    Thanks
    kyan
    Last edited by Atli; Sep 14 '07, 08:15 PM. Reason: Added [code] tags
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by kyandebishop
    Hello everybody.
    I took database course two years ago and I am having a serious problem.
    I created a table called pet with mySQL 5.0 and it has 6 fields. Among them are two fields for birth Date and death Date.
    When inserting the data I have one pet born today. I am trying to query the pet who was born today but it is not working. Here is my syntex
    SELECT *
    FROM pet
    WHERE birth Date = CURRENT_DATE( ) ;
    I get a syntex error even when I use the CURDATE() function.

    WHAT AM I DOING?
    If this query works. I want to create a TABLE month with date field and message field. Then query it in such a way that each day the message automatically be displayed on our web site as a daily devotional. I do not know if it will work or not.
    If there is anybody out there who can help me with the query above and may be another alternative of my goal please helo me.
    Thanks
    kyan
    What are your column datatypes?
    It would help if you post the error message you are getting too.

    Comment

    • kyandebishop
      New Member
      • Sep 2007
      • 4

      #3
      Datatypes are (Name) varchar(20)
      (birth Date) date

      SQL query:
      [code=mysql]
      SELECT *
      FROM `pet`
      WHERE birth Date = CURDATE( )
      LIMIT 0 , 30
      [/code]

      MySQL said:
      Code:
      #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Date = CURDATE( ) 
      LIMIT 0, 30' at line 1
      Last edited by Atli; Sep 14 '07, 08:15 PM. Reason: Added [code] tags

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by kyandebishop
        Datatypes are (Name) varchar(20)
        (birth Date) date

        SQL query:

        SELECT *
        FROM `pet`
        WHERE birth Date = CURDATE( )
        LIMIT 0 , 30

        MySQL said:

        #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Date = CURDATE( )
        LIMIT 0, 30' at line 1
        Don't put a space between birth and date.
        The column name should be BirthDate, one word.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by r035198x
          Don't put a space between birth and date.
          The column name should be BirthDate, one word.
          I would recommend this as well, but if you insist on having spaces in you names, you can do so by encapsulating them in back-ticks. For example:
          [code=mysql]
          SELECT `My ID` FROM `My Table`;
          [/code]

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Changed the thread title to better describe the problem.

            moderator

            Comment

            • kyandebishop
              New Member
              • Sep 2007
              • 4

              #7
              Thank you
              I removed the space betweb the birth Date and it worked

              Comment

              Working...