rdatelubridateformatdatetime

CYYMMDD format in R


I am trying to compare two dataframe date columns.

In the first dataframe

Name   DOB
Alex   25071986
Jane   14122002
Sujan  28021999

The DOB in ddmmyyyy format.

In the other dataframe

Name   DOB
Alex   0250786
Jane   1141202
Sujan  0280299

The DOB is in cddmmyy format. Here c represnts the century elapse from 1900. So for 1986 it is 0, for 2002 it is 1 and so on...

What I have done so far is:

1) abc <- lubridate::mdy(df1[,DOB])

which shows abc in YYYY-MM-DD format.

2) a <- strftime(abc, format = "%C%d%m%y")

which gives me CCDDMMYY for example for 2016-12-11 it gives 20111216

Which is not what I need, I need it to be 1111216 (CDDMMYY).

Can someone help?


Solution

  • As suggested by @Rui Barradas,

    sprintf("%d%s", lubridate::year(abc) %/% 100 - 19, strftime(abc, format = "%d%m%y"))
    

    did the job for me.