I'd like to convert this type of numeric values to a date but it doesn't work.
20100727
for instance
I tried to convert the numeric to character and applied this :
as.Date("20100727", "Y%d%m")
but it doesn't work.
How can I do ?
Convert Excel date to text via NotepadSelect all of the dates you want to convert and press Ctrl+C to copy them. Open Notepad or any other text editor, and paste the copied dates there. Notepad automatically converts the dates to the text format. Press Ctrl+A to select all text strings, and then Ctrl+C to copy them.
On the Data tab of the ribbon, click Text to Columns. Click Next >, then Next > again. Under 'Column data format', select Date, then select YMD from the drop-down next to the Date option button. Click Finish.
Home Number Formatting ToolsClick Home tab, then click the drop-down menu in Number Format Tools. Step 2. Select Short Date from the drop-down list. The date is instantly displayed in short date format m/d/yyyy.
You were setting wrong order of month and date values (in your code was Year, Date, Month, should be Year, Month, Date).
as.Date("20100727", "%Y%m%d")
[1] "2010-07-27"
If it is a numeric value, 20100727
, as.Date
requires it to be first converted to string, or else, would have issue
as.Date(20100727, "%Y%m%d")
Error in charToDate(x) : character string is not in a standard unambiguous format
anydate
from anytime
can internally do this conversion
library(anytime)
date1 <- anydate(20100727)
date1
#[1] "2010-07-27"
str(date1)
#Date[1:1], format: "2010-07-27"
Also, takes the character string as input
anydate("20100727")
#[1] "2010-07-27"
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