now am selecting one date from table, so from that date i have to retrieve the day of week, day of month,year... Some ways i have tried but didn''t get that, actually i had tried with current date. time = Time.new time.wday time.month.. so how to pass one date,which is from table and find the above stuffs..? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ycOok77OcPkJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2012 09:06, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > now am selecting one date from table, so from that date i have to retrieve > the day of week, day of month,year... Some ways i have tried but didn''t get > that, actually i had tried with current date. > > time = Time.new > time.wday > time.month.. > > so how to pass one date,which is from table and find the above stuffs..?are you saying that time.wday did not work? $ irb ruby-1.8.7-p302 > time=Time.new => Thu Feb 02 09:11:24 +0000 2012 ruby-1.8.7-p302 > time.wday => 4 ruby-1.8.7-p302 > time.month => 2 ruby-1.8.7-p302 > Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On Thu, Feb 2, 2012 at 10:06 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > now am selecting one date from table, so from that date i have > to retrieve the day of week, day of month,year... Some ways i have tried > but didn''t get that, actually i had tried with current date. > > time = Time.new > time.wday > time.month.. > > so how to pass one date,which is from table and find the above stuffs..? >Time and Date are quite different. Think seriously on your business need what you really need, a Time or a Date. if you need a _date_ e.g. start_date of a contract, don''t use Time, it will get confusing when local time gets involved. The concept of contract_start_date => "1 Feb 2012" is different from the concept of contract_start_time => "1 Feb 2012 00:00:00+00" At contract_start_time (midnight in London) it is still 31 Jan 2011 7pm in NYC and the contract has _not_ started yet to NY standards ... HTH, Peter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
no, That is working... but i need like this :bill_date => u.bill_date, I want to take the day, month,year from this *u.bill_date.* can i get, if am using like this * * *:day_of_week => Time.month(u.bill_date) * * * *...........?* -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/4gLXV5QAuxoJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2012 09:20, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> no, That is working... but i need like this > > :bill_date => u.bill_date, > > I want to take the day, month,year from this u.bill_date. can i get, if am > using like this > > :day_of_week => Time.month(u.bill_date)What type is bill_date? Assuming it is a Time or Date object then you want u.bill_date.month Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
colin, The data type of bill_date is *date* * * Thank you vishnu -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/usNqgFvRODcJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2012 09:36, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> colin, The data type of bill_date is datedate is not a class type. It could be Date. Do you mean that the column type in the database is date or that it is a string containing a date or what? What does it show for the column type in schema.rb? What happens when you do bill_date.month as I suggested? By the way please remember to include the relevant parts of the previous messages in your reply otherwise it is difficult to follow the thread (particularly for those who may find the thread later and hope to learn from it). Also please insert your reply at appropriate point in previous message rather than posting at the top of the new mail. Thanks. Colin> > > Thank you > vishnu > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/usNqgFvRODcJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en.-- gplus.to/clanlaw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
colin, thanks I got it from this * :day_of_week =>u.bill_date.day,* * :day_of_month => (Date.new(Time.now.year,12,31).to_date<<(12-u.bill_date.month)).day ,* * :month_of_year =>u.bill_date.month,* * :year => u.bill_date.year* * * * * *Thank you* *vishnu* -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/71FjCgn-rsgJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
date is not a class type. It could be Date. Do you mean that the column type in the database is date or that it is a string containing a date or what? What does it show for the column type in schema.rb? What happens when you do bill_date.month as I suggested? By the way please remember to include the relevant parts of the previous messages in your reply otherwise it is difficult to follow the thread (particularly for those who may find the thread later and hope to learn from it). Also please insert your reply at appropriate point in previous message rather than posting at the top of the new mail. Thanks. Colin>Sorry i forgot that, i will follow that way in next time.... Thank you> Thank you > vishnu > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ZvskyJyT4bkJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2012 09:55, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> colin, thanks > > I got it from this > > :day_of_week =>u.bill_date.day,Are you sure that does not give you the day of the month, I would have expected wday to give day of week, though since you still have not told use what type bill_date is then we cannot be sure.> :day_of_month => > (Date.new(Time.now.year,12,31).to_date<<(12-u.bill_date.month)).day ,As I said above I would have expected day or mday to give the day of month Colin> :month_of_year =>u.bill_date.month, > :year => u.bill_date.year-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 got it from this> :day_of_week =>u.bill_date.day, > :day_of_month => (Date.new(Time.now.year,12,31).to_date<<(12-u.bill_date.month)).day , > :month_of_year =>u.bill_date.month, > :year => u.bill_date.year * * * * *Can i use this same way to get the day, month, year from the default field created_at..**?* * * *i mean *:day_of_week =>u.created_at.day * * *i just tried that but got some error .day.. i think created_at field with timestamp. so that will be the problem...?* * * * * *thank you* *vishnu* * * * * -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HmwFCR7j4p4J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 February 2012 15:18, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> I got it from this > > > :day_of_week =>u.bill_date.day, > > :day_of_month => > (Date.new(Time.now.year,12,31).to_date<<(12-u.bill_date.month)).day , > > :month_of_year =>u.bill_date.month, > > :year => u.bill_date.year > > > Can i use this same way to get the day, month, year from the default field > created_at..?Yest> > i mean :day_of_week =>u.created_at.day > > i just tried that but got some error .day.. i think created_at field with > timestamp. so that will be the problem...?If you get an error you have to look at it and work out what it means, which is not always easy but you will get better at it with practice. It is no good asking for help here and just saying you got some error, you must provide the details, but first try and understand the error. Also read up on and experiment with the rails console, it can be very useful for trying things out, for example: $ rails console Loading development environment (Rails 3.1.3) ruby-1.8.7-p302 > u=User.first User Load (0.9ms) SELECT `users`.* FROM `users` LIMIT 1 => #<User id: 1, <snip>, created_at: "2011-11-25 22:01:46", updated_at: "2011-12-16 15:33:24", approved: true> ruby-1.8.7-p302 > u.created_at.day => 25 Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.