[R] Converting characters back to Date and Time

Enrico Schumann e@ @end|ng |rom enr|co@chum@nn@net
Wed Sep 1 07:25:52 CEST 2021


On Tue, 31 Aug 2021, Eliza Botto writes:

> DeaR useR,
>
> I read an excel column in R having Date and time (written in the same cell) as follow,
>
> 06/18/18 10:00
>
> 06/18/18 11:00
>
> 06/18/18 12:00
>
> In R environment, they are read as
>
> 43269.42
>
> 43269.46
>
> 43269.50
>
> Is there a way to covert these characters back to the original format?
>
> Thank-you very much in advance.
>
>
> Eliza Botto
>

If using a package is an option:

  library("datetimeutils")
  convert_date(c(43269.42, 43269.46, 43269.50), "excel")
  ## [1] "2018-06-18" "2018-06-18" "2018-06-18"

  convert_date(c(43269.42, 43269.46, 43269.50), "excel", fraction = TRUE)
  ## [1] "2018-06-18 10:04:48 CEST" "2018-06-18 11:02:24 CEST"
  ## [3] "2018-06-18 12:00:00 CEST"

Note that the times differ: the numbers are probably
not /displayed/ to full precision in R.

You may also want to search the archives of this list,
as this question has been discussed before.


-- 
Enrico Schumann (maintainer of package datetimeutils)
Lucerne, Switzerland
http://enricoschumann.net



More information about the R-help mailing list