Hi i need to compare zulu date and with current date example : expire_date=20130505172938Z now i need compare that date with current time example current_time= Time.now.strftime( "%y%m%d%H%M%S" ) now if current_time is 3 days behind then expire_date then do something ... .... but the problem is : i cant convert zulu time into current time .. Any help will be really appreciate .
on 2013-03-06 20:56
on 2013-03-06 21:07
probably easier to do the opposite and convert the current time to Zulu
time.
expire_date = Date.parse("20130505172938Z")
current_time = Time.now.utc
then do something with them
def days_away(from, to)
((to - from) / (60 * 60 * 24)).ceil
end
if days_away(current_time, expire_date) == 3
do_stuff
end
on 2013-03-06 21:49
Matt Mongeau wrote in post #1100427: > probably easier to do the opposite and convert the current time to Zulu > time. > Hi Thanks i am doing this #!/usr/bin/ruby require 'rubygems' require 'time' expire_date = Date.parse("20130505172938Z") current_time = Time.now.utc #puts expire_date #puts current_time def days_away(from, to) ((to - from) / (60 * 60 * 24)).ceil end if days_away(current_time, expire_date) == 3 puts "test" end but it giving me /usr/lib/ruby/1.8/date.rb:1220:in `-': expected numeric or date (TypeError) from test.rb:11:in `days_away' from test.rb:14 i tryed with .to_datetime but no luck what is i am missing???
on 2013-03-06 21:59
Sorry I should have typed
Time.parse("20130505172938Z")
not
Date.parse("20130505172938Z")
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.