Rabu, 11 Januari 2017

PHP Generate Code XXYYMMXXXX Function

This PHP function to generate patter code xxYYMMxxxx ex.GG17010002

function get_new_code_opb()
{

$code=''; // you can fill this using prev code with same pattern

$kode=substr($code, -4);
$num=(int)$kode;
$month=substr($code, -6,2);

if($num==0 || $num==null || $month!=$month_now)
{
$temp = 1;
}
else
{
$temp=$num+1;
}
if($dt==''){
$today = date('ym');
}
$id="XX".$today."".str_pad($temp, 4, 0, STR_PAD_LEFT); //XX can change into your prefix

return $id;
}

This code return by 1 if month changed

Tidak ada komentar:

Posting Komentar