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 > Should I use DATE type?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-02-11, 05:21
JosephDuffy JosephDuffy is offline
Registered User
 
Join Date: Oct 2011
Posts: 1
Should I use DATE type?

Hi,
I'm currently making a website that uses MySQL, and creates a new row for each day that the site is up. I've been using DATE for the testing so far, but I'm using the value as an output, and I don't like the format year-month-date. Can I either change the way the date is stored, to allow me to have it in the format day-month-year, or would I just have to use a VARCHAR to have it in this format? I'm assuming using a VARCHAR wouldn't let me pull the results in date order. However, if they're added in the correct order, it could work then?
I'm new to working this close the databases, so I might have some ideas here a bit wrong!
Thanks for any help,
Joseph Duffy
Reply With Quote
  #2 (permalink)  
Old 10-02-11, 06:19
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Never ever store a date in a VARCHAR column, it's more trouble than it's worth.

If you don't like the format, simply format the date value inside your application (using whatever your programming language offers) or retrieve it in a formatted way in your SQL statement using the date_format() function:

http://dev.mysql.com/doc/refman/5.5/...on_date-format
Reply With Quote
  #3 (permalink)  
Old 10-02-11, 15:07
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Dates are not stored as text. They are stored as a numeric value. How the date is presented in your SQL statement is handled by DATE_FORMAT function as mentioned above.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #4 (permalink)  
Old 10-03-11, 04:37
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
to echo others comments
store the values in a column of the appropriate type
so dates in datetime columns
numbers in an appropriate numeric column. (intgers in an integr type (tinyint,bigint,integer)
..and so on

formatting a column can be done when you extract the data eitehr in the query or the data consumer

with dates there is another especially good reason to use the datetime datatype and that is you can make use of the date time functions built into MySQL
MySQL :: MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions

right now you may only need the date values to appear on a report, but who knows if you may want to, say do a summary report based on month or year.
who knows if you want to only extract data for a specific month or a specific time period. storing the values in their proper datatype now elimiantes any possible problems down the line.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
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