"함수 next month()"의 두 판 사이의 차이

22번째 줄: 22번째 줄:
==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP prev_month()}}
{{참고|PHP next_month()}}
<source lang='php'>
<source lang='php'>
<?php
<?php
28번째 줄: 28번째 줄:
echo date("Y-m", strtotime("$mon +1 month"));
echo date("Y-m", strtotime("$mon +1 month"));
# 2019-08
# 2019-08
</source>
==R==
[[분류: R]]
{{참고|R next month}}
<source lang='r'>
require(lubridate)
mon = "2019-07"
t = as.Date(paste0(mon,'-01'))
month(t) = month(t) + 1
next_mon = format(t, "%Y-%m")
next_mon
## [1] "2019-08"
</source>
<source lang='r'>
require(lubridate)
next_mon <- function(mon) {
  t = as.Date(paste0(mon,'-01'))
  month(t) = month(t) + 1
  format(t, "%Y-%m")
}
next_mon("2019-07")
## [1] "2019-08"
next_mon("2019-12")
## [1] "2020-01"
</source>
</source>



2019년 11월 28일 (목) 23:31 판

1 개요

함수 next_month()

2 JavaScript

var d = new Date("2019-07");
d.setMonth(d.getMonth() + 1);
console.log( d.toISOString().substr(0,7) );
// 2019-08
var mon = "2019-07";
var d = new Date();
d.setFullYear(mon.substr(0,4));
d.setMonth(mon.substr(5,2));
console.log( d.toISOString().substr(0,7) );
// 2019-08

3 PHP

<?php
$mon = '2019-07';
echo date("Y-m", strtotime("$mon +1 month"));
# 2019-08

4 R

require(lubridate)
mon = "2019-07"
t = as.Date(paste0(mon,'-01'))
month(t) = month(t) + 1
next_mon = format(t, "%Y-%m")
next_mon
## [1] "2019-08"
require(lubridate)
next_mon <- function(mon) {
  t = as.Date(paste0(mon,'-01'))
  month(t) = month(t) + 1
  format(t, "%Y-%m")
}
next_mon("2019-07")
## [1] "2019-08"
next_mon("2019-12")
## [1] "2020-01"

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}