### Home Classes Methods

### In Files

- lib/dbi/utils/date.rb

### Parent

Object

### Methods

- ::new
- #to_date
- #to_s
- #to_time

### Included Modules

- Deprecated

### Files

- README

### Class/Module Index

Quicksearch

- DBI
- DBI::BaseDatabase
- DBI::BaseDriver
- DBI::BaseStatement
- DBI::Binary
- DBI::ColumnInfo
- DBI::DataError
- DBI::DatabaseError
- DBI::DatabaseHandle
- DBI::Date
- DBI::DriverHandle
- DBI::Error
- DBI::Handle
- DBI::HandleTracer
- DBI::IntegrityError
- DBI::InterfaceError
- DBI::InternalError
- DBI::NotImplementedError
- DBI::NotSupportedError
- DBI::OperationalError
- DBI::ProgrammingError
- DBI::Row
- DBI::SQL
- DBI::SQL::PreparedStatement
- DBI::StatementHandle
- DBI::Time
- DBI::Timestamp
- DBI::Type
- DBI::Type::Boolean
- DBI::Type::Decimal
- DBI::Type::Float
- DBI::Type::Integer
- DBI::Type::Null
- DBI::Type::Timestamp
- DBI::Type::Varchar
- DBI::TypeUtil
- DBI::Utils
- DBI::Utils::ConvParam
- DBI::Utils::TableFormatter
- DBI::Utils::XMLFormatter
- DBI::Warning
- Class

No matching classes.

# DBI::Date

Represents a Date.

DEPRECATED: Please use a regular Date or DateTime object.

### Attributes

day[RW]
mday[RW]
mday=[RW]
mon[RW]
mon=[RW]
month[RW]
year[RW]

### Public Class Methods

new(year=0, month=0, day=0) click to toggle source

DBI::Date.new(year = 0, month = 0, day = 0) DBI::Date.new(Date) DBI::Date.new(Time)

Creates and returns a new DBI::Date object. It's similar to the standard Date class' constructor except that it also accepts a Date or Time object.

    # File lib/dbi/utils/date.rb, line 43
    def initialize(year=0, month=0, day=0)
        case year
        when ::Date
            @year, @month, @day = year.year, year.month, year.day
            @original_date = year
        when ::Time
            @year, @month, @day = year.year, year.month, year.day
            @original_time = year
        else
            @year, @month, @day = year, month, day
        end
    end

### Public Instance Methods

to_date() click to toggle source

Returns a new Date object based on the year, month and day or, if a Date object was passed to the constructor, returns that object.

    # File lib/dbi/utils/date.rb, line 25
    def to_date
        @original_date || ::Date.new(@year, @month, @day)
    end

to_s() click to toggle source

Returns a DBI::Date object as a string in YYYY-MM-DD format.

    # File lib/dbi/utils/date.rb, line 30
    def to_s
        sprintf("%04d-%02d-%02d", @year, @month, @day)
    end

to_time() click to toggle source

Returns a new Time object based on the year, month and day or, if a Time object was passed to the constructor, returns that object.

    # File lib/dbi/utils/date.rb, line 19
    def to_time
        @original_time || ::Time.local(@year, @month, @day, 0, 0, 0)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.