#' 处理日期数据
#'
#' @param startDate 开始日期
#' @param length 个数
#'
#' @return 返回值
#' @export
#'
#' @examples
#' date_add();
date_add <- function(startDate='1984-01-01',length=5) {
#针对数据类型进行处理
startDate <- as.date(startDate);
#处理数据,包含当天数据,用于HR处理
index <- 1:length -1;
#生成序列
res <- startDate+index;
return(res);
}
#' 生成日期序列
#'
#' @param startDate 开始日志
#' @param endDate 结束日期
#'
#' @return 返回值
#' @export
#'
#' @examples
#' date_minus();
date_minus <-function(startDate='1984-01-01',endDate='1984-01-05'){
#针对数据类型进行处理
startDate <- as.date(startDate);
endDate <- as.date(endDate);
indexLen <- endDate-startDate;
res <- startDate+ 0:indexLen;
return(res);
}
#' 获取日期数据
#'
#' @param n 重复次数
#'
#' @return 返回值
#' @export
#'
#' @examples
#' getDate()
getDate <- function(n=1) {
res <- as.character(Sys.Date())
res <- rep(res,n)
return(res)
}
#' 处理EXCEL日常字段
#'
#' @param 数字
#'
#' @return 返回值
#' @export
#'
#' @examples
#' excel_date()
excel_date <- function(x) {
x1 = as.Date('1900-01-01')
value = x1 + x -2
res = as.character(value)
return(res)
}
#' 获取当前日期的年份
#'
#' @return 返回值
#' @export
#'
#' @examples
#' getYear()
getYear <-function(){
a = Sys.Date()
b = as.POSIXlt(a)
res = as.character(b$year+1900)
return(res)
}
#' 获取当前日期的月份
#'
#' @return 返回值
#' @export
#'
#' @examples
#' getMonth()
getMonth <-function(){
a = Sys.Date()
b = as.POSIXlt(a)
res = as.character(b$mon+1)
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.