Hey, This may be a simple question, but I just wanted to make sure I was doing it right. I need to store just the year in my database - i.e. vacation entitlement year = 2008 Should I store it using ''date'' and leave the month and day as ''0'' 2008-00-00 or should i store it as an integer? Many Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well actualy it depends a lot on what you wanna do with this year data...could you precise a little what is your goal? On 20 feb, 17:02, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey, > > This may be a simple question, but I just wanted to make sure I was > doing it right. > > I need to store just the year in my database - i.e. vacation entitlement > year = 2008 > > Should I store it using ''date'' and leave the month and day as ''0'' > > 2008-00-00 > > or should i store it as an integer? > > Many Thanks > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
CiriusMex wrote:> Well actualy it depends a lot on what you wanna do with this year > data...could you precise a little what is your goal? > > On 20 feb, 17:02, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>I am building a little application to manage our company holiday entitlement. When adding a new user, the form will allow the admin user to enter the holiday entitlement for next couple of years: e.g. -------------- Name: John Smith Entitlement for year starting 2008: 24 [days] Entitlement for year starting 2009: 25 [days] ------------- So, in theory, my table will look like: ------------- id user_id year entitlement ------------- -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ok, so the year will just be stored as information (I mean you''ll just use it to display the information on a page) no? If it''s like that you store it as a varchar or integer I think. But if you will need to process the year in other functions well it should be better to store it as a year. When creating a new line on your database you can use the Date.today function to get the current date, after the function strftime will help you to display only the year: @year = <your_object>.year.strftime("%Y") displaying @year in your html.erb page you''ll only see the year from the date, just as you want to. On 20 feb, 17:32, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> CiriusMex wrote: > > Well actualy it depends a lot on what you wanna do with this year > > data...could you precise a little what is your goal? > > > On 20 feb, 17:02, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > I am building a little application to manage our company holiday > entitlement. > > When adding a new user, the form will allow the admin user to enter the > holiday entitlement for next couple of years: > > e.g. > > -------------- > Name: John Smith > > Entitlement for year starting 2008: 24 [days] > Entitlement for year starting 2009: 25 [days] > ------------- > > So, in theory, my table will look like: > > ------------- > id > user_id > year > entitlement > ------------- > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
CiriusMex wrote:> Ok, so the year will just be stored as information (I mean you''ll just > use it to display the information on a page) no? > If it''s like that you store it as a varchar or integer I think. But if > you will need to process the year in other functions well it should be > better to store it as a year. > When creating a new line on your database you can use the Date.today > function to get the current date, after the function strftime will > help you to display only the year: > @year = <your_object>.year.strftime("%Y") > > displaying @year in your html.erb page you''ll only see the year from > the date, just as you want to. > > On 20 feb, 17:32, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thank you for the reply. I am going to use the year to calculate other things. So will it be ok to leave the the day and the month as ''0'' in the ''date'' format? 2008-00-00 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> CiriusMex wrote: >> Ok, so the year will just be stored as information (I mean you''ll >> just >> use it to display the information on a page) no? >> If it''s like that you store it as a varchar or integer I think. But >> if >> you will need to process the year in other functions well it should >> be >> better to store it as a year. >> When creating a new line on your database you can use the Date.today >> function to get the current date, after the function strftime will >> help you to display only the year: >> @year = <your_object>.year.strftime("%Y") >> >> displaying @year in your html.erb page you''ll only see the year from >> the date, just as you want to. >> >> On 20 feb, 17:32, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Thank you for the reply. > > I am going to use the year to calculate other things. > > So will it be ok to leave the the day and the month as ''0'' in the > ''date'' > format? > > 2008-00-00I wouldn''t. Mysql doesn''t seem to care. PostgreSQL does. philip=# create table foo (d date); CREATE TABLE philip=# insert into foo values (''2008-00-00''); ERROR: date/time field value out of range: "2008-00-00" HINT: Perhaps you need a different "datestyle" setting. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Actually if you gonna use the date to make some things you can store it as a simple integer, or as a date but not with 0 as day and month but 1 as 0 is no month or day ^^ On 20 feb, 18:12, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > CiriusMex wrote: > >> Ok, so the year will just be stored as information (I mean you''ll > >> just > >> use it to display the information on a page) no? > >> If it''s like that you store it as a varchar or integer I think. But > >> if > >> you will need to process the year in other functions well it should > >> be > >> better to store it as a year. > >> When creating a new line on your database you can use the Date.today > >> function to get the current date, after the function strftime will > >> help you to display only the year: > >> @year = <your_object>.year.strftime("%Y") > > >> displaying @year in your html.erb page you''ll only see the year from > >> the date, just as you want to. > > >> On 20 feb, 17:32, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > Thank you for the reply. > > > I am going to use the year to calculate other things. > > > So will it be ok to leave the the day and the month as ''0'' in the > > ''date'' > > format? > > > 2008-00-00 > > I wouldn''t. Mysql doesn''t seem to care. PostgreSQL does. > > philip=# create table foo (d date); > CREATE TABLE > philip=# insert into foo values (''2008-00-00''); > ERROR: date/time field value out of range: "2008-00-00" > HINT: Perhaps you need a different "datestyle" setting.- Ocultar texto de la cita - > > - Mostrar texto de la cita ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t see a big advantage in storing it as a date, if you only want to store the year why not store it as an integer? if then you need to do some calculations you can always convert it to whatever you want. On Feb 20, 11:56 pm, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> CiriusMex wrote: > > Ok, so the year will just be stored as information (I mean you''ll just > > use it to display the information on a page) no? > > If it''s like that you store it as a varchar or integer I think. But if > > you will need to process the year in other functions well it should be > > better to store it as a year. > > When creating a new line on your database you can use the Date.today > > function to get the current date, after the function strftime will > > help you to display only the year: > > @year = <your_object>.year.strftime("%Y") > > > displaying @year in your html.erb page you''ll only see the year from > > the date, just as you want to. > > > On 20 feb, 17:32, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Thank you for the reply. > > I am going to use the year to calculate other things. > > So will it be ok to leave the the day and the month as ''0'' in the ''date'' > format? > > 2008-00-00 > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Scott, Why don''t you use the default created/updated_at fields and just format the output to present only the year? Cheers, Sazima On Feb 20, 8:02 pm, Scott Holland <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hey, > > This may be a simple question, but I just wanted to make sure I was > doing it right. > > I need to store just the year in my database - i.e. vacation entitlement > year = 2008 > > Should I store it using ''date'' and leave the month and day as ''0'' > > 2008-00-00 > > or should i store it as an integer? > > Many Thanks > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Store it as an integer, this will surely help you once you need to query it. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Fri, Feb 20, 2009 at 8:02 PM, Scott Holland <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey, > > This may be a simple question, but I just wanted to make sure I was > doing it right. > > I need to store just the year in my database - i.e. vacation entitlement > year = 2008 > > Should I store it using ''date'' and leave the month and day as ''0'' > > 2008-00-00 > > or should i store it as an integer? > > Many Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---