Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2005
    Posts
    27

    Unanswered: Dateformat: YYYY-MM

    Hi,

    (how) can i create a column with a format like "YYYY-MM"?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    CHAR(7)

    what do you need it for? there might be another way to get what you want
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2005
    Posts
    27
    Hi,

    i want to store values, which are related to a month in a year. The exact day is not interesting. My first idee was to use the date format as providesd by mysql (YYYY-MM-DD), an fill the DD part with a dummy value. But if someone else will mantain this later, surely the question will come "why did you use always a dummy for DD". Therefore i dont want to store data which has no sense.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, as a matter of fact, you can store values in a DATE column using 00 as the day!!

    it's certainly not standard, but mysql lets you do it, check the manual for examples

    otherwise, i would use two columns, a SMALLINT for the year and a TINYINT for the month
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jan 2005
    Posts
    27
    hi,

    that's both not the solution i hoped for, but if ther's no other i think i'll choose the one with two columns

    Thanx

    roli

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    what were you hoping for?

    and what's so wrong with a DATE column with values '1998-12-00'?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Jan 2005
    Posts
    27
    Quote Originally Posted by r937
    what were you hoping for?
    I thought there would be a way to define a column with a format like "YYYY-MM"

    Quote Originally Posted by r937
    and what's so wrong with a DATE column with values '1998-12-00'?
    I dont want to store datn which has no information (-00). If there's no direct way provided by the DB, i'll have to find on by myself (or with your help: two clumns).
    Further or later someone (or me) will think "what the hell does -00 meen?"

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    well, you could always just show them the page in the manual where -00 is explained

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Jan 2005
    Posts
    27
    You're right, but this solution just work's as long as my DBA sets the SQL-Modus to NO_ZERO_IN_DATE.
    Two coulm's will work for ever

  10. #10
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, but only for approx 63,000 years, unless you plan ahead now and use INTEGER instead of SMALLINT

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  11. #11
    Join Date
    Jan 2005
    Posts
    27
    Ok, if that's gonna happen i'll quit

Posting Permissions

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