Java版
public static int getAgeByIdcard(String idcard){
String birthday = idcard.substring(6, 14); //19990101
String nowDate = DateUtil.getNowDate(); //20200101
int birthdayTime = Integer.parseInt(birthday);
int nowDateTime = Integer.parseInt(nowDate);
int duration = nowDateTime - birthdayTime;
double age = duration / 10000.0;
return Double.valueOf(Math.floor(age)).intValue();
}
MySQL版
age = FLOOR((#{today}-substring(idcard,7,8))/10000)
网友评论