I am trying to check whether a given date is in dd/mm/yyyy format or not in R
language and also whether it is a valid date or not at the same time. I want output in TRUE or FALSE format, e.g.
Input:
date<- c('12/05/2016','35/11/2067','12/52/1000')
Output:
TRUE FALSE FALSE
You can use this function:
IsDate <- function(mydate, date.format = "%d/%m/%y") {
tryCatch(!is.na(as.Date(mydate, date.format)),
error = function(err) {FALSE})
}
IsDate(date)
[1] TRUE FALSE FALSE
Original source of the code here.
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With