Ron, I hope this will be helpful.
require(lubridate, quietly = TRUE) require(stringr, quietly = TRUE) test_date_str1 <- "6/3/2012" test_date_1 <- mdy(test_date_str1, quiet = TRUE) test_date_1 test_date_str2 <- "2-3-2011" my_date_strings <- c(test_date_str1, test_date_str2) my_dates <- mdy(my_date_strings, quiet = TRUE) make_date <- function(.date, sep = "/") { str_c(month(.date), sep, day(.date), sep, year(.date)) } make_date(test_date_1) make_date(my_dates) A slightly more complex function allows you to take more advantage of the lubridate package. require(lubridate, quietly = TRUE) require(stringr, quietly = TRUE) test_date_str1 <- "6/3/2012" test_date_1 <- mdy(test_date_str1, quiet = TRUE) test_date_1 test_date_str2 <- "2-3-2011" my_date_strings <- c(test_date_str1, test_date_str2) my_dates <- mdy(my_date_strings, quiet = TRUE) make_date <- function(.date, sep = "/", label = FALSE, abbr = TRUE) { str_c(month(.date, label, abbr), sep, day(.date), sep, year(.date)) } make_date(test_date_1) make_date(my_dates) make_date(my_dates, sep = "-", label = TRUE) make_date(my_dates, sep = " ", label = TRUE, abbr = FALSE) R. Mark Sharp, Ph.D. Director of Primate Records Database Southwest National Primate Research Center Texas Biomedical Research Institute P.O. Box 760549 San Antonio, TX 78245-0549 Telephone: (210)258-9476 e-mail: msh...@txbiomed.org<mailto:msh...@txbiomed.org> On Dec 26, 2012, at 8:38 PM, Jim Holtman <jholt...@gmail.com<mailto:jholt...@gmail.com>> wrote: what happens with 25/12/2012? Sent from my iPad On Dec 26, 2012, at 20:22, arun <smartpink...@yahoo.com<mailto:smartpink...@yahoo.com>> wrote: Hi, gsub("^\\d(.*/)\\d(.*/.*)<smb://d(.*/.*)>","\\1\\2<smb://1//2>",format(asd,"%d/%m/%Y")) #[1] "3/1/2012" A.K. ----- Original Message ----- From: Ron Michael <ron_michae...@yahoo.com<mailto:ron_michae...@yahoo.com>> To: jim holtman <jholt...@gmail.com<mailto:jholt...@gmail.com>> Cc: "r-help@r-project.org<mailto:r-help@r-project.org>" <r-help@r-project.org<mailto:r-help@r-project.org>> Sent: Wednesday, December 26, 2012 2:25 PM Subject: Re: [R] Working with date Thanks Jim for your reply. However I want "3/1/2012" not "03/01/2012" Any idea ? Thanks ----- Original Message ----- From: jim holtman <jholt...@gmail.com<mailto:jholt...@gmail.com>> To: Ron Michael <ron_michae...@yahoo.com<mailto:ron_michae...@yahoo.com>> Cc: "r-help@r-project.org<mailto:r-help@r-project.org>" <r-help@r-project.org<mailto:r-help@r-project.org>> Sent: Thursday, 27 December 2012 1:01 AM Subject: Re: [R] Working with date forgot you were asking for mdy format # interchange day and month format(asd, format = '%d/%m/%Y') [1] "03/01/2012" On Wed, Dec 26, 2012 at 2:14 PM, jim holtman <jholt...@gmail.com<mailto:jholt...@gmail.com>> wrote: try this: asd <- as.Date("2012-01-03") asd [1] "2012-01-03" format(asd, format = '%m/%d/%Y') [1] "01/03/2012" On Wed, Dec 26, 2012 at 1:31 PM, Ron Michael <ron_michae...@yahoo.com<mailto:ron_michae...@yahoo.com>> wrote: asd <- as.Date("2012-01-03") -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. ______________________________________________ R-help@r-project.org<mailto:R-help@r-project.org> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org<mailto:R-help@r-project.org> mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.