본문 바로가기

잡다한 기술

[PHP] 만 나이 계산기




# 소스 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<title>Hello PHP World</title>
</head>
<body>
    <div class="container">
        <?php 
            $now_year = 2016;
            $now_month = 11;
            $now_day = 29;
            
            $birth_year = 1992;
            $birth_month = 10;
            $birth_day = 12;
            
            if($birth_month < $now_month){
                $age = $now_year - $birth_day;
            }else if($birth_month == $now_day){
                if($birth_day <= $now_day){
                    $age = $now_year - $birth_year;
                }else{
                    $age = $now_year - $birth_year-1;
                }
            }
        ?>    
        
        오늘 날짜 : <?= $now_year ?> 년 <?= $now_month ?> 월 <?= $now_day ?> 일<br/>
        출생 연월일 : <?= $birth_year ?> 년 <?= $birth_month ?> 월 <?= $birth_day ?> 일생<br/>
        만 나이 : <?= $age ?>
    </div>
</body>
</html>
cs

해당 소스는 제가 학생때 연습삼아 만든 소스 입니다.