Date format

43 views
Skip to first unread message

docw...@gmail.com

unread,
Feb 23, 2021, 8:36:08 AMFeb 23
to hydromad users

Hi everyone

I have a problem with the date format, I am using the% d-% m-% Y format with chron but the latter converts them to m / d / Y format, and that causes me errors afterwards.

> library(hydromad)

> setwd(system.file("essai4", package = "hydromad"))

> file.show("pqt_10-2000.csv")

> pqtdat <- read.table("pqt_10-2000.csv", sep = ",")

> names(pqtdat) <- c("Date","P", "Q", "E")

> datetimes = as.character(pqtdat$Date)

> library(chron)

> Date_dt = as.chron(as.POSIXct(datetimes, format="%Y-%m-%d %H:%M", usetz = FALSE))

> head(Date_dt)

[1] (09/22/00 22:00:00)  (09/22/00 23:00:00)  (09/23/00 00:00:00)  (09/23/00 01:00:00) (09/23/00 02:00:00)  (09/23/00 03:00:00)       [here is the error i am talking to]    

>library(zoo)

>pqtdat_zoo = zoo(pqtdat[, 2:4], order.by=Date_dt)

>pqtdat_zoo$Q = convertFlow(pqtdat_zoo$Q, from="m3/s", to="mm / hour", area.km2 = 1957)

>Sefra = zoo(pqtdat_zoo, frequency=24)

>ts2000s <- window(Sefra, start = "2000-10-24 00:00",

end = "2000-10-24 23:00")

Error in convert.dates(dates., format = fmt, origin. = origin.) :

  format m/d/y may be incorrect

De plus : Warning message:

In unpaste(dates., sep = fmt$sep, fnames = fmt$periods, nfields = 3) :

  wrong number of fields in entry(ies) 1

best regards

Alex

unread,
Feb 23, 2021, 1:13:43 PMFeb 23
to hydromad users
It looks like the error may be caused by using characters for your start and end for your window.

Try this:

window(Sefra,
       start = as.chron(as.POSIXct("2000-10-24 00:00:00")),
       end = as.chron(as.POSIXct("2000-10-24 23:00:00")))
Reply all
Reply to author
Forward
0 new messages