473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

datatype with data like 2008-09

232 100+
what datatype should i take for field financial year with data like 2008-09?
kindly suggest.................
Nov 18 '09 #1

✓ answered by Atli

Hey.

I would recommend using two DATE fields, one for the starting year and one for the end year. It is better than using a single INT, from a data-integrity point of view, as MySQL will actually be able to treat the dates as dates, rather than numbers, and putting two dates into a single field violates the first rule of database normalization.

That aside, you should always store your data inside your database in a neutral format. Storing two dates in a "financial" format is not neutral, and might even require your front-end to parse the data out of the database - to separate the two dates to use them by themselves - which is just horrific.

If you are concerned about storage space requirements, there is hardly any need. Each DATE field takes only 3 bytes, while a single INT takes 8. You could probably get away with using a MEDIUMINT, which takes 3 bytes, but saving 3 bytes of space is hardly worth sacrificing the integrity of the data and the benefits you get from use the DATE type.

And if you want your query to return the data as '2008-09', you could just have it construct it out of the two dates:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.     CONCAT(
  3.         YEAR(`first_date`), '-', 
  4.         DATE_FORMAT(`second_year`, '%y')
  5.     ) AS 'financial_date' 
  6. FROM `my_table`;
Although, using the front-end application to do such formatting is probably better, all things considered.

4 2034
mwasif
802 Expert 512MB
Use an INT field and store year and month as 200809.
Nov 19 '09 #2
kkshansid
232 100+
@mwasif
these are not year & month its financial year 2008-09(march 2008 to march 2009)
Nov 21 '09 #3
Atli
5,058 Expert 4TB
Hey.

I would recommend using two DATE fields, one for the starting year and one for the end year. It is better than using a single INT, from a data-integrity point of view, as MySQL will actually be able to treat the dates as dates, rather than numbers, and putting two dates into a single field violates the first rule of database normalization.

That aside, you should always store your data inside your database in a neutral format. Storing two dates in a "financial" format is not neutral, and might even require your front-end to parse the data out of the database - to separate the two dates to use them by themselves - which is just horrific.

If you are concerned about storage space requirements, there is hardly any need. Each DATE field takes only 3 bytes, while a single INT takes 8. You could probably get away with using a MEDIUMINT, which takes 3 bytes, but saving 3 bytes of space is hardly worth sacrificing the integrity of the data and the benefits you get from use the DATE type.

And if you want your query to return the data as '2008-09', you could just have it construct it out of the two dates:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.     CONCAT(
  3.         YEAR(`first_date`), '-', 
  4.         DATE_FORMAT(`second_year`, '%y')
  5.     ) AS 'financial_date' 
  6. FROM `my_table`;
Although, using the front-end application to do such formatting is probably better, all things considered.
Nov 23 '09 #4
Atli
5,058 Expert 4TB
@mwasif
That is not a good idea, seeing as an INT field is 250% larger than a DATE field, which is specifically tailored to store such data.
You could use a MEDIUMINT, which is equal in size to a DATE field, but by doing that you lose all the benefits the DATE types get, and you compromise the integrity of the data. (Integer fields could just as well accept invalid dates, while a DATE field would not.)

You should always try to use the DATE types for dates.
Nov 23 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: tdmailbox | last post by:
I have a production application that I am building some upgrades using a second (empty) copy the database. A few of the upgrades included changing the datatypes of a few fields from varchar to...
0
by: SoYouKnowBrig | last post by:
Hi All, I am using Microsoft.ApplicationBlocks.Cache.CacheManager to persist a System.Data.Dataset object. This Dataset object has a DataTable that is created from an existing DataTable using...
10
by: andrewcw | last post by:
I read in a earlier post that I can get the column of a grid to sort by datetime if the column type was set as Date I deserialize my XML and one attribute of the XSD has type as dateTime but upon...
2
by: ad | last post by:
I use ado.net to fill a Excel wroksheet into a DataTable. The data in the Excel wroksheet is digital. After the data filled into the DataTable, the DataType of each column is set to Double, but...
8
by: Vinod | last post by:
Hi, I have a stored procedure which expects a varbinary datatype. How can i pass a varbinary datatype from asp.net directly to the stored procedure. I tried using the Convert function in Sql...
3
by: Sri | last post by:
In VB, to know the field type of a column stored in a recordset the command I use is If rsQuery.Fields(k).Type = adCurrency Then How will I achieve the same in ASP.net. I could not find a...
1
by: Savas Ates | last post by:
I have a column in my table BizdekiFiyat . The datatype = float length =8 (to save money values).. It is impossible to change these attributes for some reasons. It has records like This ...
4
by: Orchid | last post by:
How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? ...
4
by: loisk | last post by:
Hi, I am facing some problems using date expression as string datatype. Here's clip of my code. The (Intvdate) is string datatype in the MySQL linked table. Private Sub...
0
by: pykie101 | last post by:
Hi, I'm having a problem, I'm using PostgreSQL V8.3.3-1, Npgsql and Visual studio 2008 c#. I'm passed a dictionary of key, value (key been a string, value been an object). The code works fine...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.