0

I am working on finding the number of months a particular person has starting to work until the present. The start date of the person is in "m/d/y h:m" format. For example:

Person        Start Time 
A             9/23/2014 14:25 
B             7/14/2004 8:32
C             2/4/2010 22:01

The goal is to have the number of months the person has been working until as of right now.

Person        Start Time          Has been working for (months):
A             7/4/2014 14:25      48
B             7/4/2008 8:32       120
C             7/4/2010 22:01      96

i know that have to use Sys.Time but also not sure how to delete(ignore) the specific time such as the hour and minute(hh:mm) from the complete date set, but I am not sure what to do.

Since the Rcode is going to process thousands of people in a csv file, what is the best way to calculate this the most efficient way? Thanks

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • it s related but its quite different because the format is different. Im still learning R so it would be great if there is anyone can give some input example on how to efficiently solve this. thanks – governator5410 Jul 04 '18 at 08:18
  • Using *lubridate* package, convert to date `df1$StartTime <- mdy_hm(df1$StartTime)`, then get months `df1$WorkingMonths <- interval(df1$StartTime, now()) %/% months(1)` – zx8754 Jul 04 '18 at 08:36
  • 1
    Applying the first two solution from the linked question lead to the desired result. You will have to convert your `StartTime` to a proper date format with `as.Date(df$StartTime, "%m/%d/%Y")` though. – Jaap Jul 04 '18 at 08:37

0 Answers0