Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create sequence of date on every last day of month

I’m trying to create a sequence of date on every last day of the months.
For example, the start date is "2018-01-31". I want to create a sequence of every last day of month since the start date.

[1] "2018-01-31" "2018-02-28" "2018-03-31" "2018-04-30" "2018-05-31" "2018-06-30"

I’m trying to use this syntax:

seq(as.Date("2018-01-31",format="%Y-%m-%d"),by="month",length.out=6)

But it gives this output instead:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[1] "2018-01-31" "2018-03-03" "2018-03-31" "2018-05-01" "2018-05-31" "2018-07-01"

How to get the last day of every months since the start date?

>Solution :

If you want last day of month, instead of start from 2018-01-31, try

seq(as.Date("2018-02-01",format="%Y-%m-%d"),by="month",length.out=6) -1
[1] "2018-01-31" "2018-02-28" "2018-03-31" "2018-04-30" "2018-05-31" "2018-06-30"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading