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:

  1. difftime() takes difftime(end_time, start_time), not other way around
  2. %i deals hours in 1-12 opposed %h deals 0-23
  3. the hour followed colon in string, not dot
  4. there fractional part seconds %os, instead of %s
  5. a " %p" @ end take in am/pm

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -