Skip to content

help on date objects...

3 messages · akshay kulkarni, Eric Berger, Rui Barradas

#
Dear members,
                             WHy is the following code returning NA instead of the date?
[1] NA


Thanking you,
Yours sincerely,
AKSHAY M KULKARNI
#
as.Date("2022-01-02", origin="1900-01-01", format="%Y-%d-%m")

On Sun, Jul 28, 2024 at 7:24?AM akshay kulkarni <akshay_e4 at hotmail.com>
wrote:

  
  
#
?s 05:23 de 28/07/2024, akshay kulkarni escreveu:
Hello,

There are several reasons for your result.

1. You have 4 digits year but format %y (lower case = 2 digits year) It 
should be %Y
2. Your date has '-' as separator but your format doesn't have a separator.

Also, though less important:

1. You don't need argument origin. This is only needed with numeric to 
date coercion.
2. Are you sure the format is YYYY-DD-MM, year-day-month?


as.Date("2022-01-02", format = "%Y-%d-%m")
#> [1] "2022-02-01"

# note the origin is not your posted origin date,
# see the examples on Windows and Excel
# dates in help("as.Date")
as.Date(19024, origin = "1970-01-01")
#> [1] "2022-02-01"


Hope this helps,

Rui Barradas