difftime - R timediff - 22-JAN-16 04.56.14.325000000 PM -
i want calculate duration between 2 date of data frame formatted per below:
start_date_time
22-jan-16 04.56.14.325000000 pm
end_date_time
23-jan-16 05.56.14.325000000 am
i run below command:
jm16$diff <- difftime(strptime(jm16$start_date_time, format = "%d-%b-%y %h.%m.%s"), strptime(jm16$end_date_time, format = "%d-%b-%y %h.%m%s"), units="mins")
however, ends entire field of jm16$diff "na". please advise make mistake?
thanks
han
the formula need use is:
jm16$diff <- difftime(strptime(jm16$end_date_time, format="%d-%b-%y %i:%m.%os %p"), strptime(jm16$start_date_time, format="%d-%b-%y %i:%m.%os %p"), units="mins")
this corrects following issues:
difftime()
takesdifftime(end_time, start_time)
, not other way around%i
deals hours in 1-12 opposed%h
deals 0-23- the hour followed colon in string, not dot
- there fractional part seconds
%os
, instead of%s
- a
" %p"
@ end take in am/pm
Comments
Post a Comment