Zero disappearing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    Zero disappearing

    I'm updating an entry in a mysql table using phpmyadmin and when I try to enter a month (i.e., 09) into a field mysql drops the zero and leaves only the 9.

    How can I stop this?

    ****UPDATE***** *

    Resolved:
    OK, I just changed the table row from INT to VARCHAR. Works.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    That is not a good idea, to be honest.

    When you are storing dates, you should use either the DATE, TIME, DATETIME or TIMESTAMP data types.
    Don't split the dates up into induvidual parts (year, month, day, etc..). That will just take up additional space and make the data harder to work with.

    If you just need to store a month, use INT. If you need to print numbers < 10 with the extra zero, either have your front end add it before printing it or use the ZEROFILL keyword when you create the field.

    But you should NOT create a numeric field as VARCHAR just to store it in the right format. Your database should be responsible for storing the data, not making it look pretty. That is a job for your front-end software.

    Comment

    Working...