Excel如何把身份证升为18位,提取出生年月,性别,年龄
- 2022-07-22
- 来源/作者: Wps Office教程网/ 菜鸟图库
- 153 次浏览
以下假设身份证号码放在A1单元格中。
1.从身份证号码中提取出生年月日:
假如身份证号数据在A1单元格,在B1单元格中编辑公式=IF(LEN(A1)=15,"19"&MID(A1,7,2)&MID(A1,9,2)&MID(A1,11,2),MID(A1,7,4)&MID(A1,11,2)&MID(A1,13,2))这样输出格式就都是19821010这种格式了。
可以通过下述操作,完成形如1978-12-24样式的出生年月日自动提取:假如身份证号数据在C2单元格=IF(LEN(A1)=15,MID(A1,7,2)&"-"&MID(A1,9,2)&"-"&MID(A1,11,2),MID(A1,7,4)&"-"&MID(A1,11,2)&"-"&MID(A1,13,2))。
2.从身份证号码中提取性别:
=IF(MOD(MID(A1,15,3),2),"男","女")
3.从身份证号码中提取年龄:
=DATEDIF(TEXT(MID(A1,7,LEN(A1)*2/3-4),"0-00-00"),TODAY(),"Y")
4.将15位身份证升位为18位:
=IF(LEN(A1)=15,(REPLACE(A1,7,,19))&(INDEX({1,0,"X",9,8,7,6,5,4,3,2},1,(MOD(SUM(MID(REPLACE(A1,7,,19),1,1)*7+MID(REPLACE(A1,7,,19),2,1)*9+MID(REPLACE(A1,7,,19),3,1)*10+MID(REPLACE(A1,7,,19),4,1)*5+MID(REPLACE(A1,7,,19),5,1)*8+MID(REPLACE(A1,7,,19),6,1)*4+MID(REPLACE(A1,7,,19),7,1)*2+MID(REPLACE(A1,7,,19),8,1)*1+MID(REPLACE(A1,7,,19),9,1)*6+MID(REPLACE(A1,7,,19),10,1)*3+MID(REPLACE(A1,7,,19),11,1)*7+MID(REPLACE(A1,7,,19),12,1)*9+MID(REPLACE(A1,7,,19),13,1)*10+MID(REPLACE(A1,7,,19),14,1)*5+MID(REPLACE(A1,7,,19),15,1)*8+MID(REPLACE(A1,7,,19),16,1)*4+MID(REPLACE(A1,7,,19),17,1)*2),11))+1)),A1)