Browse | Submit A New Snippet | Create A Package

 

Simple date manipulation examples

Type:
Sample Code (HOWTO)
Category:
Calendars
License:
GNU General Public License
Language:
Ruby
 
Description:
Howto use & manipulate dates in Ruby.

Versions Of This Snippet::

James McCarthy
Snippet ID Download Version Date Posted Author Delete
500.0022004-08-27 10:35James McCarthy
Changes since last version::
changed cwday() to wday()
490.0012004-08-24 15:56James McCarthy

Download a raw-text version of this code by clicking on "Download Version"

 


Latest Snippet Version: :0.002

require 'date' #at the top of the script

aNewDate=Date::new(2004,8,12) #year,month,day

aNewDate::to_s #gives u the saved date as a string

aNewDate=aNewDate::+1 #increases by 1 day

aNewDate=aNewDate::-1 #decreases by 1 day

day=aNewDate::wday() # gives the day of the week as a number, sun=0, mon=1....
week=aNewDate::cweek() #gives the week of year as a number
   
toDaysDate=Date::today() #creates a Date object with todays date
		

Submit a new version

You can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..