Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round an POSIXct date up to the next day

Tags:

r

posixct

I have a question similar to Round a POSIX date (POSIXct) with base R functionality, but I'm hoping to always round the date up to midnight the next day (00:00:00).

Basically, I want a function equivalent to ceiling for POSIX-formatted dates. As with the related question, I'm writing my own package, and I already have several package dependencies so I don't want to add more. Is there a simple way to do this in base R?

like image 981
Eli Sander Avatar asked Feb 19 '23 13:02

Eli Sander


1 Answers

Maybe

trunc(x,"days") + 60*60*24

> x <- as.POSIXct(Sys.time())
> x
[1] "2012-08-09 18:40:08 BST"
> trunc(x,"days")+ 60*60*24
[1] "2012-08-10 BST"
like image 93
shhhhimhuntingrabbits Avatar answered Mar 03 '23 06:03

shhhhimhuntingrabbits