[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

string to date

misiek

1/18/2006 10:51:00 PM

hmm

from the form I got date variables 'time_in' and 'time_out'
<%= form_remote_tag(
:url => { :action => :"check_sick", :controller => "hour" ,:id => @user
, :super_id => @super_user},
:confirm => "Are you sure you ? ") %>
from<%= date_select("time_out","time_out")%> - to <%=
date_select("time_in","time_in")%>
<input type="submit" value="sick_days" class="text_table">
</form>


by pressing the sick_days I go to check_sick action
and here I need to deduct a date
basicly I need numer of days

like '2006-12-02' - '2006-12-01' = 1
how to do that
I was trying like @params['time_in'] - @params['time_out']
but this is not correctbecause @params is a string .
I was trying also use string_to_date(@params['time_in']) but i does not
work too
2 Answers

Dan Kohn

1/19/2006 1:10:00 AM

0

irb(main):005:0> (Date.parse('2006-12-02') -
Date.parse('2006-12-01')).to_i
=> 1

misiek

1/19/2006 4:59:00 AM

0

Dan Kohn wrote:
> irb(main):005:0> (Date.parse('2006-12-02') -
> Date.parse('2006-12-01')).to_i
> => 1
>


@int_days = Date.parse(@params['time_in']).to_i -
Date.parse(@params['time_out']).to_i
render_text @int_days

which is @params['time_in'] string for sure like 2006-12-12
shoud it works ? because does not ..