Message-ID: <87y28g50kf.fsf@enricoschumann.net>
Date: 2021-09-01T05:25:52Z
From: Enrico Schumann
Subject: Converting characters back to Date and Time
In-Reply-To: <AS8P194MB099979E9FD39C8A3705261579ACC9@AS8P194MB0999.EURP194.PROD.OUTLOOK.COM> (Eliza Botto's message of "Tue, 31 Aug 2021 20:26:01 +0000")
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