1

I have to export a table, with columns of text, and 3 columns with the date type. But I can't convert the date columns to date. They are originally in "character" format. The data frame is as follows:

Fecha de ejecucion

2022-05-31

2022-05-31

2022-05-31

2022-05-31

I want to move on to date with the formula:

BtotalSinPublico$’Fecha de ejecucion’ <- as.Date(BtotalSinPublico$’Fecha de ejecucion’)

The query: Class(BtotalSinPublico$’Fecha de ejecucion’) It results in: [1] Date

But when I stand in the column of the data frame it enunciates the format 'unknown'. And when I export it:

WriteXLS(BtotalSinPublico, ExcelFileName = str_c("PrevisionesNiif_",Fecha,".xls)

The columns are formatted in General.

  • Dates are *stored* as a number but can be *presented* in a nice date format. You will probably want to replace `Fecha` in the document name with `format(Fecha, xxx)` where `xxx` is the date format you want. See this [help page](https://r-lang.com/r-date-format/) for info on formatting dates and this chapter of the [r4ds book](https://r4ds.had.co.nz/dates-and-times.html) for more info. – DanY Jul 05 '22 at 18:59
  • + You might want to use another package to get the date formatting in excel. See e.g. https://stackoverflow.com/questions/38960571/write-dates-to-excel-properly-from-r – harre Jul 05 '22 at 19:02
  • test the following code -> BtotalSinPublico$`Fecha de ejecucion` <- Sys.Date() BtotalSinPublico$`Fecha de ejecucion` <- format(BtotalSinPublico$`Fecha de ejecucion`, format = "%Y-%m-%d") and returns the "character" format as a result. – Aldana Sanchez Jul 05 '22 at 19:18
  • poor all these codes and none worked: BtotalSinPublico$`Fecha de ejecucion` <- as.POSIXct(BtotalSinPublico$`Fecha de ejecucion`, format = '%Y-%m-%d') BtotalSinPublico$`Fecha de ejecucion` <- as.Date('2022-05-31', format = '%Y-%m-%d') BtotalSinPublico$`Fecha de ejecucion` <- anytime(BtotalSinPublico$`Fecha de ejecucion`) BtotalSinPublico$`Fecha de ejecucion` <- Sys.Date() BtotalSinPublico$`Fecha de ejecucion` <- format(BtotalSinPublico$`Fecha de ejecucion`, format = "%Y-%m-%d") – Aldana Sanchez Jul 06 '22 at 14:03

0 Answers0