1. yyyymmdd 를 이용하여 내일 구하기 (응용가능)
sub next_date{
$tstr="";
$tval="";
$time="";
$tstr = $_[0];
@tval = ( $tstr =~ m|(\d{4})(\d{2})(\d{2})| );
$time = timelocal( 0, 0, 0, $tval[2], $tval[1] - 1, $tval[0] );
$trtime =strftime ( "%Y%m%d", localtime( $time + 24 * 3600 ) ), "\n";
return $trtime;
}
2. yyyymmddhhmiss를 이용하여 epoch time 구하기
sub make_time{
my $rcvdate = $_[0];
my $s_year=substr($rcvdate,0,4)-1900;
my $s_mon=substr($rcvdate,4,2)-1;
my $s_day=substr($rcvdate,6,2);
my $s_hour=substr($rcvdate,8,2);
my $s_min=substr($rcvdate,10,2);
my $s_sec=substr($rcvdate,12,2);
my $gap = mktime ($s_sec,$s_min,$s_hour,$s_day,$s_mon,$s_year);
return $gap
}
3. 월을 비교해서 실제 연도 구하기
# dispatchtime과 completime이 다른 해애 시작 될경우
# 두 값을 비교하여 year값을 구하는 함수
sub date_realyear{
my $rcvdispatch="";
my $rcvdispatch=$_[0];
my $dismon="";
my $rcvcomplete="";
my $rcvcomplete=$_[1];
my $common="";
$dismon = substr($rcvdispatch,4,3);
$dismon =$des{$dismon};
if(substr($dismon,1,1) eq ""){$dismon = "0$dismon";}
$common = substr($rcvcomplete,4,3);
$common =$des{$common};
if(substr($common,1,1) eq ""){$common = "0$common";}
$rdistime = "$year$dismon";
$rcomtime = "$year$common";
if($rdistime > $rcomtime){
$dyear=$year-1;
$cyear=$year;
}else{
$dyear=$year;
$cyear=$year;
}
return $dyear,$cyear;
}
4. 연월일 구하기
# 연월일을 뽑아 낼 수 있도록 만든 함수.
sub date_ymd{
my $rcvdate="";
my $rcvdate=$_[0];
my $tryear=$_[1];
my $trmon="";
my $trday="";
my $trhour="";
my $trmin="";
my $trsec="";
my $trtime="";
$trmon = substr($rcvdate,4,3);
$trmon =$des{$trmon};
if(substr($trmon,1,1) eq ""){$trmon = "0$trmon";}
$trday = substr($rcvdate,8,2);
$trday =~ s/ //;
if(substr($trday,1,1) eq ""){$trday = "0$trday";}
$trhour = substr($rcvdate,11,2);
if(substr($trhour,1,1) eq ""){$trhour = "0$trhour";}
$trmin = substr($rcvdate,14,2);
if(substr($trmin,1,1) eq ""){$trmin = "0$trmin";}
$trsec = substr($rcvdate,17,2);
if(substr($trsec,1,1) eq ""){$trsec = "0$trsec";}
$trtime = "$tryear$trmon$trday";
# return $trtime
return $trtime;
}
5. 연월일시분초 구하기
# date_ymdhms 함수는 Fri Apr 8 10:15:41 -> yyyymmddhh24miss 형식으로 변경해주는 함수
# 정확한 time을 구하기 위한 함수
sub date_ymdhms{
my $rcvdate="";
my $rcvdate=$_[0];
my $tryear=$_[1];
my $trmon="";
my $trday="";
my $trhour="";
my $trmin="";
my $trsec="";
my $trtime="";
$trmon = substr($rcvdate,4,3);
$trmon =$des{$trmon};
if(substr($trmon,1,1) eq ""){$trmon = "0$trmon";}
$trday = substr($rcvdate,8,2);
$trday =~ s/ //;
if(substr($trday,1,1) eq ""){$trday = "0$trday";}
$trhour = substr($rcvdate,11,2);
if(substr($trhour,1,1) eq ""){$trhour = "0$trhour";}
$trmin = substr($rcvdate,14,2);
if(substr($trmin,1,1) eq ""){$trmin = "0$trmin";}
$trsec = substr($rcvdate,17,2);
if(substr($trsec,1,1) eq ""){$trsec = "0$trsec";}
$trtime = "$tryear$trmon$trday$trhour$trmin$trsec";
# return $trtime
return $trtime;
}
'Language > Perl' 카테고리의 다른 글
[Perl] -help option sub함수 (0) | 2016.04.25 |
---|---|
[Perl] date 형식 yyyymmddhh24miss 로 변경 함수 (0) | 2016.04.08 |
[per] today, yesterday, nextday (3) | 2016.03.10 |
[perl] hash of hash (0) | 2016.03.10 |
[perl] update 쿼리 (0) | 2016.03.10 |