views:

62

answers:

1

Forgive me if this is a simple answer.

But how do you get a Date from a DataMapper property. For example:

require 'rubygems'
require 'sinatra'
require 'datamapper'

class Test
    include DataMapper::Resource

    property :id, Serial
    property :created_at, Date
end

get '/:id' do
    test = Test.get(1)

    test.created_at = ?
end
A: 

You can access it with the functions from http://ruby-doc.org/core/classes/DateTime.html

For example:

require 'rubygems'
require 'sinatra'
require 'datamapper'

class Test
    include DataMapper::Resource

    property :id, Serial
    property :created_at, Date
end

get '/:id' do
    test = Test.get(1)

    test.created_at.strftime(fmt='%F %T')
end

will return a date formatted YYYY-MM-DD HH:MM:SS

Does that help?

Will Luongo