2026, 새로운 도약을 시작합니다.

경력 년월수 구하기

경력 시작날짜와 종료 날짜를  및 경력 환산율을 입력 받아서 년 개월 일수로 구하는 계산식입니다.

로직은 제가 개발한거 아니고 엑셀함수를 php로 변환만 한거에요..

공무원 보수등의 업무지침에 따라 력에 의한 방법에 의하여 계산합니다.

민번 제16조 참고하세요.

자바스크립트로 페이지 로딩 후 계산을 할려고 해봤는데 날짜가 너무 복잡하고 01월과 1월도 차이가 계산이 되서 php로 작성했습니다.

저는 ajax로 해서 시작날짜와 종료 날짜 경력 환산율을 던져 줘서 다시 받아오는 형태로 했습니다.

ajax 그누보드에 네임체크인가? 그거 가져다가 변경해서 사용했습니다.

[code]

<?php
include_once('../../../common.php');

$start_date = strip_tags($_POST['start']);
$end_date = strip_tags($_POST['end']);
$like_record = strip_tags($_POST['record']);

if(!$like_record) $like_record = 100;
$like_record = $like_record / 100;

 // 년수 구하기.
 
    // 조건 1 만년이면 1년을 가산합니다.
    if(substr($start_date,4,2) == 1 && substr($start_date,6,2) == 1 &&
    substr($end_date,4,2) == 12 && substr($end_date,6,2) == 31)
 { $value_1 = 1; } else { $value_1 = 0; }
  
    // 조건 2 종료월일 시작월일의 전일에 미달하면 1년을 감산합니다.
    $value2_date = date('Ymd', strtotime(substr($end_date,0,4)."-".substr($start_date,4,2)."-".substr($start_date,6,2)));

 if($end_date < date("Ymd", strtotime($value2_date." -1 day")))
 { $value_2 = 1; } else { $value_2 = 0; }
   
    // 종료년 - 시작년 + 조건 1 - 조건 2
     $final_year = substr($end_date,0,4) - substr($start_date,0,4) + $value_1 -$value_2;

  // 월수 구하기.
 
    //조건 1 만월이면  1월을 가산합니다.
    if(substr($start_date,6,2) == 1 && $end_date == substr($end_date,0,6).date('t', strtotime($end_date)))
 { $month_value_1 =1; } else { $month_value_1 = 0; }
   
    //조건 2 종료월이 시작월의 전일에 미달하면 12월을 가산합니다.
     if($end_date < date("Ymd", strtotime($value2_date." -1 day")))
  { $month_value_2 = 12; } else { $month_value_2 = 0; }
 
    //조건 3 종료일이 사작일의 전일에 미달하면 1월을 감산합니다.

     if(substr($end_date,6,2) < substr($start_date,6,2) -1)
  { $month_value_3 = 1; } else { $month_value_3 = 0; }
   
    //조건 4 말일로 한 달이 만료되면 다시 1월을 가산합니다.
  
      if($end_date == substr($end_date,0,6).date('t', strtotime($end_date)) &&
                date('t', strtotime($end_date)) < substr($start_date,6,2) -1
  )
      { $month_value_4 = 1; } else { $month_value_4 = 0; }
   
    // (종료월 - 시작월  + 조건1 + 조건2 - 조건3  + 조건4)/12 나머지 값

      $final_month = ( substr($end_date,4,2) - substr($start_date,4,2) + $month_value_1 + $month_value_2 -                $month_value_3 + $month_value_4 ) % 12;
   
       // 일수 구하기.
    // 조건.
       if( // 전체적 if
      (
    substr($start_date,6,2) == 1 && $end_date == substr($end_date,0,6).date('t', strtotime($end_date))
   )
      ||
      substr($end_date,6,2) == substr($start_date,6,2) -1
      ||
     (
      $end_date == substr($end_date,0,6).date('t', strtotime($end_date)) &&
      date('t', strtotime($end_date)) < substr($start_date,6,2) -1
     )
        
    ) // 전체 if 끝
     { $final_day = 0;}
      else { //else 시작
       
         if(substr($start_date,6,2) -1 < date('d', strtotime($end_date)))
     { $day_value_1 = substr($start_date,6,2) -1; }
             else { $day_value_1 = 0; }
         
          if( substr($end_date,6,2) < substr($start_date,6,2) -1 &&
        substr($start_date,6,2) -1 < date('t', strtotime("-1 month", mktime(0,0,0, date(substr($end_date,4,2)), 1, date(substr($end_date,0,4)))))
      )
        { $day_value_2 = date('t', strtotime("-1 month", mktime(0,0,0, date(substr($end_date,4,2)), 1, date(substr($end_date,0,4))))) - substr($start_date,6,2) + 1 ; }
              else { $day_value_2 = 0; }
   
           if(substr($start_date,6,2) + 29 == substr($end_date,6,2) ||
      (date('t', strtotime("-1 month", mktime(0,0,0, date(substr($end_date,4,2)), 1,  date(substr($end_date,0,4))))) == 31 &&
       substr($start_date,6,2) -2 == substr($end_date,6,2)
      )
              )
         { $day_value_3 = 1; } else { $day_value_3 = 0; }
   
         $final_day = substr($end_date,6,2) - $day_value_1 + $day_value_2 - $day_value_3 ;
          } //else 끝


// 환산율 구하기.
//몫: ($b - ($b % $a)) / $a;
//나머지: $b % $a;


 $percent_year_1 = floor($like_record * $final_year);
 $percent_year_2_1 = floor(($like_record * $final_year - floor($like_record * $final_year)) * 12);
 $percent_year_2_2 = floor($like_record * $final_month);
 $percent_year_2_3 = floor((($final_year * $like_record - floor($final_year * $like_record)) * 12 -                         floor(($final_year  * $like_record - floor($final_year * $like_record)) * 12)) * 30 );
 $percent_year_2_4 = floor(($final_month * $like_record - floor($final_month * $like_record)) * 30 );
 $percent_year_2_5 = floor($final_day * $like_record);
     
  
 $percent_year_2 = (($percent_year_2_3 + $percent_year_2_4 + $percent_year_2_5) -(($percent_year_2_3 + $percent_year_2_4 + $percent_year_2_5) % 30 )) / 30;
      
 $percent_year_3 = (($percent_year_2_1 + $percent_year_2_2 + $percent_year_2) - (($percent_year_2_1 + $percent_year_2_2 + $percent_year_2) % 12)) / 12;
   
 $percent_year =  $percent_year_1 + $percent_year_3;


 $percent_month = ( $percent_year_2_1 + $percent_year_2_2 + $percent_year_2 ) % 12 ;

 $percent_day = ( $percent_year_2_3 + $percent_year_2_4 + $percent_year_2_5 ) % 30 ;
 

$out = sprintf("%02d",$percent_year)."년 ".sprintf("%02d",$percent_month)."월 ".sprintf("%02d",$percent_day)."일";  
$out1 = $value2_date;
die("{\"subject\":\"$out\",\"content\":\"$out1\"}");
?>

[/code]

|

댓글 1개

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,598
2741 3일 전 조회 111
2740 4일 전 조회 103
2739 1주 전 조회 209
2738 1주 전 조회 217
2737 1주 전 조회 181
2736 1주 전 조회 280
2735 3주 전 조회 281
2734 3주 전 조회 263
2733 1개월 전 조회 265
2732 1개월 전 조회 301
2731 1개월 전 조회 267
2730 1개월 전 조회 226
2729 1개월 전 조회 356
2728 1개월 전 조회 245
2727 1개월 전 조회 422
2726 1개월 전 조회 256
2725 1개월 전 조회 330
2724 1개월 전 조회 358
2723 1개월 전 조회 267
2722 1개월 전 조회 300
2721 1개월 전 조회 211
2720 2개월 전 조회 304
2719 2개월 전 조회 307
2718 2개월 전 조회 202
2717 2개월 전 조회 336
2716 2개월 전 조회 202
2715 2개월 전 조회 311
2714 2개월 전 조회 273
2713 2개월 전 조회 376
2712 2개월 전 조회 289
🐛 버그신고