Forum: Ruby on Rails Convert Date to Time

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris (Guest)
on 2006-03-01 11:43
Hi,

How do i convert a Date to a Time??

I have a date returned from sql and i need to be able to use handy
functions like next_week or beggining of week.

Any help appreciated
Thanks,
Chris
F4405aa9f526aeea20541ca1aa3705e6?d=identicon&s=25 Mathias Stjernström (Guest)
on 2006-03-01 12:08
(Received via mailing list)
Hi,

sql_date = "2006-03-01 11:59:01"

var = Time.local(*ParseDate.parsedate(sql_date))
var.next_week

Cheers!

Mathias Stjernstrom
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris (Guest)
on 2006-03-01 13:46
Thanks Mathias!,

but what i was looking for is this :

a=Time.new
d=a.to_date()

AND

a=Date.new
t=a.to_time()

Chris
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Mikkel Bruun (Guest)
on 2006-03-01 14:00
(Received via mailing list)
mb>ruby script/console
Loading development environment.
>> t = Time.new
=> Wed Mar 01 13:59:31 W. Europe Standard Time 2006
>> d = t.to_date
=> #<Date: 4907591/2,0,2299161>
>> d.class
=> Date
>> t = d.to_time
=> Wed Mar 01 00:00:00 W. Europe Standard Time 2006
>> t.class
=> Time
>>


On Wednesday, March 01, 2006, at 1:46 PM, Chris wrote:
>t=a.to_time()
>
>Chris
>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails


Mikkel Bruun

www.strongside.dk    - Football Portal(DK)
nflfeed.helenius.org - Football News(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
This topic is locked and can not be replied to.