달력관련 질문 입니다. 채택완료
꽁치입니다
4년 전
조회 1,568
</p>
<p><div class="input-group input-group-sm">
<span><input type="text" id="date_02" name="wr_data[contract_period_01]" value="<?php echo $wr_data['contract_period_01']; ?>" required class="form-control input-sm" placeholder="선택하세요"></span>
<span class="input-group-addon" style="border-left:0px; border-right:0px;">-</span>
<span><input type="text" id="date_03" name="wr_data[contract_period_02]" value="<?php echo $wr_data['contract_period_02']; ?>" required class="form-control input-sm" placeholder="선택하세요"></span>
</div></p>
<p><label><input type="text" class="form-control input-sm" name="wr_data[contract_period_03]" value="<?php echo $wr_data['contract_period_03']; ?>" /></label></p>
<p> </p>
<p> </p>
<p><script></p>
<p>$(function() {</p>
<p> $("#date_02,#date_03").datepicker({</p>
<p> changeMonth: true,
language: "ko",
todayHighlight: true,
autoclose: true,
changeYear: true,
dateFormat: "yy-mm-dd",
yearRange: "c-100:c+10"</p>
<p> });
});
</script></p>
<p> </p>
<p>
위의 달력을 계약기간 이라 할때 , 기간의 합을 $wr_data['contract_period_03']에 월(月) 단위로 정수로 표시 하고 싶습니다.
예) 2021-07-06 ~ 2021-09-05 일때는 정수로 2개월,
예) 2021-07-06 ~ 2021-09-06 일때는 정수로 3개월, 1일이 오버 되면 무조건 1달로 추가
혹시 가능 할까요?? 도움 부탁 드립니다.^^
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
4년 전
https://stackoverflow.com/questions/13416894/calculate-the-number-of-months-between-two-dates-in-php
참고하세요.
로그인 후 평가할 수 있습니다
답변에 대한 댓글 5개
�
꽁치입니다
4년 전
�
엑스엠엘
4년 전
$date1 = '2000-01-25';
$date2 = '2010-02-20';
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
====
$ts1 = strtotime( $wr_data['contract_period_01']); // 작은 값
$date2 = '2010-02-20';
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
====
$ts1 = strtotime( $wr_data['contract_period_01']); // 작은 값
�
꽁치입니다
4년 전
[code]
<?php
$date1 = '2000-01-25';
$date2 = '2010-02-20';
$ts1 = strtotime( $wr_data['contract_period_01']); // 작은 값
$ts2 = strtotime( $wr_data['contract_period_02']); // 큰 값
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
?>
<label><?php echo $diff; ?> 개월</label>
[/code]
이렇게 해 보았는데요.. 안되는군요,, ㅡㅡ;
뭐가 문제인지... 제가 문제인지... 암튼 답변 주셔서 고맙습니다.^^
<?php
$date1 = '2000-01-25';
$date2 = '2010-02-20';
$ts1 = strtotime( $wr_data['contract_period_01']); // 작은 값
$ts2 = strtotime( $wr_data['contract_period_02']); // 큰 값
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$diff = (($year2 - $year1) * 12) + ($month2 - $month1);
?>
<label><?php echo $diff; ?> 개월</label>
[/code]
이렇게 해 보았는데요.. 안되는군요,, ㅡㅡ;
뭐가 문제인지... 제가 문제인지... 암튼 답변 주셔서 고맙습니다.^^
�
엑스엠엘
4년 전
echo $wr_data['contract_period_01'];
echo $wr_data['contract_period_02'];
하셔서 값이 원하는 포맷인지 확인해 보세요.
echo $wr_data['contract_period_02'];
하셔서 값이 원하는 포맷인지 확인해 보세요.
�
꽁치입니다
4년 전
아. 역시 어렵네요. 해결은 안됐지만, 좀 더 검색해 보고 응용해보고 완성하겠습니다.^^
친절히 답변 달아 주셔서 감사합니다.^^
친절히 답변 달아 주셔서 감사합니다.^^
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
알려주신 좌표가서 계속 보고는 있는데 , 한 가지
$date1 = '2021-06-01';
$date2 = '2021-09-01';
에서 '2021-06-01' 를 '$wr_data['contract_period_01']' 의 입력값으로 바꾸려고 별짓을 다 해 봤는데, 적용 불가 입니다. 혹시 라시는 방법 있으신지요?
$wr_data['contract_period_01'] 가 아니면 , 여분필드도 괜찮은데요....