Today is my 10,000 days old birthday

I’ve been calculated my day of 10,000 days old birthday in R since few days ago.
I found that to calculate this in R is quite simple.

My birthday to 10,000 days old birthday:

> as.Date("1986-09-21") + 10000
[1] "2014-02-06"

Birthday to days since my birthday:

> Sys.Date() - as.Date("1986-09-21")
Time difference of 10000 days

Just for reference, below is an R function to convert a birthday to age.

# Birthday to age
birthday2age <- function(birthday){
  td.y <- as.integer(format.Date(Sys.Date(),"%Y"))
  td.m <- as.integer(format.Date(Sys.Date(),"%m"))
  td.d <- as.integer(format.Date(Sys.Date(),"%d"))
  bd.y <- as.integer(format.Date(birthday,"%Y"))
  bd.m <- as.integer(format.Date(birthday,"%m"))
  bd.d <- as.integer(format.Date(birthday,"%d"))
  return(td.y-bd.y-(td.m<bd.m||(td.m==bd.m&&td.d<bd.d)))
}
> birthday2age("1986-09-21")
[1] 27

cake
Happy birthday with R.

Reference:
年齢の計算は暗算でもできる

Advertisements

Data Science and Software Engineering

Posted in R

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: