If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Dateformat: YYYY-MM

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-06, 06:45
roli roli is offline
Registered User
 
Join Date: Jan 2005
Posts: 27
Dateformat: YYYY-MM

Hi,

(how) can i create a column with a format like "YYYY-MM"?
Reply With Quote
  #2 (permalink)  
Old 08-04-06, 07:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
CHAR(7)

what do you need it for? there might be another way to get what you want
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-04-06, 07:20
roli roli is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 08-04-06, 07:28
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-04-06, 07:37
roli roli is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 08-04-06, 07:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
what were you hoping for?

and what's so wrong with a DATE column with values '1998-12-00'?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 08-04-06, 07:58
roli roli is offline
Registered User
 
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?"
Reply With Quote
  #8 (permalink)  
Old 08-04-06, 08:06
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
well, you could always just show them the page in the manual where -00 is explained

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-04-06, 08:17
roli roli is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 08-04-06, 09:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
yes, but only for approx 63,000 years, unless you plan ahead now and use INTEGER instead of SMALLINT

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #11 (permalink)  
Old 08-04-06, 11:14
roli roli is offline
Registered User
 
Join Date: Jan 2005
Posts: 27
Ok, if that's gonna happen i'll quit
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On