Date is wrongly converted when imported into RStudio from Oracle - r

I'm working with an Oracle database and have a connection in RStudio using the ROracle package. For some reason some dates are converted when imported into R through either dplyr or dbGetQuery.
A date field that in the database reads 2018-01-01, turns into 2018-01-31 23:00:00 when imported. The same is the case with 2018-02-01 that is converted to 2018-02-28 23:00:00.
What is really weird is that if I export the data frame to an excel spread sheet using openxlsx the dates are again displayed correctly.
Anybody who knows what is going on, or could point me in the right direction? The column is formatted as POSIXct, and I´ve tried changing locale and timezone. I´ve also tried converting the date column with as.Date, but with no luck.

The problem had to do with how ROracle converts dates when importing. The dates for the winter months where imported as CET while the rest of the dates where imported as CEST.
Found the explanation here: https://www.oralytics.com/2015/05/r-roracle-and-oracle-date-formats_27.html

Related

WP All Import date issue

I am importing an excel file that has a date field with the following format: dd/mm/YYYY
It imports the data OK, however it does something strange with the dates. If the day is higher than 12, then it takes the current date.
I found this on the log:
WARNING: unrecognized date format ``, assigning current date
For example: the date 08/04/2020 is imported ok because 08 <= 12, however the date 23/02/2020 is not imported because 23 is not <= 12, and then it takes the current date.
Any ideas about what is happening?
This issue can get confusing with Excel, since typically, if the system is set for U.S. locales, Excel converts standard European date format in day-month-year to some version of month/day/year. In other words, tThe forward slash usually indicates American format, which is month first, as in April 9, 2022 or 04/09/22. You can force day/month/year, and apparently that was done for your file or system, but that's not an expected or standard format.
Without examining All Import code in detail, I'd say the behavior you describe implies it is presuming the standard usage. I'd therefore recommend that you try converting your date column before attempting imports, but how to do that efficiently would probably be more an Excel question than a WordPress question, unless you are able in your version of All Import to perform a custom conversion on the field.
A trick that sometimes works on this type of problem is copy-pasting Excel data into a Google Sheet, then downloading as CSV, without ever opening the file in your system before re-uploading. Google Sheets is pretty good about such conversions in general, but no guarantees: Your source file might defeat it in this case.
I had the same issue. Change the dates in your csv file to mm/dd/yyyy and when it imports it will automatically convert to dd/mm/yyyy if that is what your WP website is set up to use.
Only numbers lower than 12 will work the way you are importing because there are only 12 months in a year and it is reading you dd as mm.

Write_csv output issues: yyyymmddThhmmssZ instead of yyyymmdd hhmmss

I have been messing around with the datetime formatting, as I have data that goes through daylight savings time. The csv files I read in skip an hour in the spring and then repeat one in the fall. This seems to mess up a loop I am using. So I am tying to see if telling R what timezone the data is in PST and PDT, will help.
I was playing with reading in the data:
read_csv("file.csv", locale = locale(tz = "America/Los_Angeles"))
I read in of the data inputs the proper timezone, but now I have issues using write_csv.
When I write my datafile it outputs ie. "2011-11-30T14:20:51Z" in the csv datetime column.
I tried to reinstall R/RSTUDIO, readr, and to read in new data without this formatting and write_csv; all with no luck! I am still learning so any tips would be appreciated, thank you!

What is the correct date format for writexl

What is the correct date format for the new writexl package? I tried it on lubridate dates, and the resulting Excel spreadsheet contains strings of the form yyyy-mm-dd (i.e. not Excel dates).
The purpose of the writexl package is to essentially create a mirror image of an R table in an excel file format. So having data in one of the usual R date/time formats like as.Date, as.POSIXct, etc. won't translate to a date format shifting from YYYY-mm-dd to d/m/y while being exported to excel. If you'd like it in a more standard excel date/time format in the excel file, it's best to convert it prior to exporting it with something like the strftime() function, like this:
require(writexl)
write_xlsx(
data.frame(date=strftime(c("2017-09-10","2017-09-11","2017-09-12"),"%d/%m/%y")),
"~/Downloads/mydata.xlsx")
Output (in xlsx file):
date
10/09/17
11/09/17
12/09/17
Edit:
If you'd like the data to be an Excel date format once it's in the new file, then adding as.POSIXct() to the above will ensure that.
It worked when I converted my dates to POSIXct dates using as.POSIXct.

Parsing Date Time in different formats automatically in R

I have been working in R and parsing Date Time using as.POSIXct with specific format strings. But today I noticed that as.POSIXct converted "8/1/2017 11:00:28 PM" into "2017-08-01 11:00:28" with format="%m/%d/%Y %H:%M". The PM was not present in format and time were read wrongly since PM was not considered. Is this expected?
Is there a way in R to know if the parsing is done properly?
Also are there any R packages that can handle datetime in different formats & parse properly.

export 'datetime.date' to excel via xlwings

I have a pandas dataframe with a datetime.date column.
I try to export the dataframe to excel via xlwings.
I get the following error message:
AttributeError: 'datetime.date' object has no attribute 'microsecond'
I am quite confident the error takes place in the translation between the datetime.date type column into the excel equivalent.
The obvious solution would be convert the column into datetime which should map to the excel timestamp (16.02.2015 00:00:00 -> 42051).
Are there alternatives to that? I find quite odd that there isn't a Date type in Excel. Are there workarounds? Add a dummy time of the day to the date just to convert the column into datetime for the sake of exporting it to excel is not the (type) safest solution.
This is a bug as logged here and admittedly it's a shame it hasn't been resolved yet.
However, in the case of a Pandas DataFrame, you can for now workaround the issue by converting the column into a Pandas datetime column:
df.DateColumn = pandas.to_datetime(df.DateColumn)

Resources