dates from xlsx to data frame to another data frame shows as # instead of dates

I have an xlsx file with a few tabs, some of these tabs their columns have dates in them.
I imported each of these tab into R data frame. Then I join all these data frame together (called ALL) to create one Huge data frame.

I then created a separate data frame (call new_Frame) and created some headers that have similar data frame columns to the ALL data frame, some of the columns are date columns such as date1, date2 etc.

I then created a program to loop and populate the new_Frame with data from the ALL data frame. I noticed the dates that was date types in excel, after moving the data around the date has turn into numbers that doesn't look like dates. Below is how the dates appear in new_Frame data frame.

I don't know why.. that is.. Please advise !

dateALTERED

I resolved the issue above by using this code where I format the number into date.
However I have to use the date variable and minus it by 1 because if I don't, the day is one day ahead.
It has to do with the time, it seems like dates in data frame has a time that is before 12:00 am, however format as date the time is 12:00 am making it one day ahead.

format(as.Date(date-1, format='%m/%d/%y')
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.