2

mainly I just need to know what the commands are to get month, day and year, first day of month and last day of month. I should be able to figure it out from there. I've built a nice one in PHP but I would rather use ruby since using a database is so much easier in ruby.

So if you can point me in the right direction.

4 Answers 4

1

ActiveSupport (part of the Rails framework, but can be used separately) extends the standard library Date class with features fit for your purpose. If you don't have Rails already installed, just install ActiveSupport:

gem install activesupport

Then in your code you can use it like this:

require 'rubygems'
require 'active_support'

# Get today's date
today = Date.today

# These are in the standard library Date class
today.year
 => 2010 
today.month
 => 7
today.day
 => 10 
today.wday
 => 6 

# These are added by ActiveSupport
date = today.beginning_of_month
 => Thu Jul 01 2010
date.end_of_month
 => Sat Jul 31 2010
date.prev_month
 => Tue, 01 Jun 2010 
date.next_month
 => Sun, 01 Aug 2010 
date + 2.months
 => Wed, 01 Sep 2010 
date - 2.months
 => Sat, 01 May 2010 

See the documentation for details.

0

Why you want to create when there is already plugins for that ref CalendarDateSelect Demo for mini-calendar AND event_calendar for event showing in caledar format.

1
  • becuse i like to do things my way not someone elses way i would gladly look at it and tear it apart to do what i want! Aug 13, 2010 at 6:37
0

http://ruby-doc.org/core/classes/Date.html describes Ruby's Date class. The wday function will get the day-of-the-week of an arbitrary Date.

http://www.techotopia.com/index.php/Working_with_Dates_and_Times_in_Ruby describes how to use Dates in their entirety.

0

Also checkout the cal gem. It only does the basics for you so you can focus on building the calendar yourself. Stuff like determining the days in the calendar (usually a few days from the previous month, the days in the current month, and a few days from the next month) and starting the week on a day other than Sunday.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.