Skip to content
Prev 388577 / 398530 Next

Help with Converting Excel Times to R

Thank you very much!  That worked.  I didn't need the unclass(as.Date...) as the as.POSIXlt required me to use an origin to make the transformation.

The working code is as follows:
as.POSIXct((times*86400),origin="1904-01-01",tz="America/Chicago")
[1] "2021-07-20 08:30:00 CDT" "2021-07-20 08:39:59 CDT"


I've never heard of the "1904-01-01" origin, only the "1899-12-30" origin for excel.  Nor did I know about the multiplication of 86400.

Thank you again! 


Shawn Way

-----Original Message-----
From: Jim Lemon <drjimlemon at gmail.com> 
Sent: Wednesday, July 21, 2021 6:09 PM
To: Shawn Way <sway at empowerpharmacy.com>
Cc: r-help at r-project.org
Subject: Re: [R] Help with Converting Excel Times to R

Hi Shawn,
I don't have any trouble with this:

times<-c("7/20/21 13:30","7/20/21 13:40") strptime(times,"%m/%d/%y %H:%M",tz="GMT") [1] "2021-07-20 13:30:00 GMT" "2021-07-20 13:40:00 GMT"

I suspect that Excel is causing the problem. Try changing the format of the date column to "Text" and work on the character representation of the dates.

Jim
On Thu, Jul 22, 2021 at 8:49 AM Shawn Way <sway at empowerpharmacy.com> wrote:
Message-ID: <SA1PR13MB4878D59BD9F6D7D45A80329FC3E39@SA1PR13MB4878.namprd13.prod.outlook.com>
In-Reply-To: <CA+8X3fUr19-5x0Uz4drLUi9LzbyiM5WBkCwY5m-BqS51G7b87A@mail.gmail.com>