学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

[求助]根据身份证号码位数如何判断年龄和性别?

[求助]根据身份证号码位数如何判断年龄和性别?

身份证号码新旧位数不同,如何取号码的位数来判断年龄段和性别?
老号码好像是16位,新号码是18位,且后面是有一个校验位数。
SQL如何写可以同时满足以下条件:
1:年龄段(20-40岁)
2:性别(女性)

TOP

这个首先要了解身份证号码的特征才行,我不太了解。只知道有一段数字是出生日期。
                      坚定的信念.

TOP

select colunms from tablename where substr(colunms,7,8)>=19670904 and substr(columns,7,8)<=20070904 and substr(columns,18,1)/2=0
這個是以新的身份證為基准,字段為你存儲身份證的字段。

[此贴子已经被作者于2007-9-5 10:48:10编辑过]

你微笑的面對整個世界,整個世界也將會微笑的面對你。

TOP

天下归心

TOP

我在VB中用过这个,你可以搜索一下。能够正确判断15 18位的身份证号码,包括出生年月日的判断,后4位的判断等等。

IT精英如同彩票:平凡的人像5块也中不到一样普遍,努力一点你中了5元保了个本。奖金越高,机率也就越小,付出的也越多,盖茨如同500万一样稀有。虽然每天忙碌而平凡,但我努力成为精英,做梦中了500万。 MyAudiA8@Gmail.com

TOP

回复:(tibetshu)[求助]根据身份证号码位数如何判断...

可以借鉴一下
地球人的缺点与恶习集一身,小心感染不良恶习

TOP

回复:(tibetshu)[求助]根据身份证号码位数如何判断...

package web_service;

public class javaBean1
{
private String code_15;//15位身份证号码
private String code_18;//18位身份证号码
private String sex;//性别
private String birthday;//生日

public javaBean1() {
}

//输入
public void inpt(String code2)
{
//330127860701001
this.code_15=code2;
this.sex=code2.substring(14);
this.birthday=code2.substring(6,8)+"年"+code2.substring(9,10)+"月"+code2.substring(11,12)+"日";
}
public String Exception_()
{
if(this.code_15.length()==15)
{
return "go";
}
else
{
return "error";
}
}

//输出性别
public String outSex()
{
return this.sex;
}

//输出生日
public String outBirthday()
{
return this.birthday;
}

//输出15位身份证号码
public String outCode_15()
{
return this.code_15;
}

//输出18位身份证号码
public String outCode_18()
{
String num_1_6 = code_15.substring(0, 6);
String num_7_15 = code_15.substring(6, code_15.length());
this.code_18 = num_1_6 + "19" + num_7_15;
int newshuzi[] = new int[17];
char[] cha = this.code_18.toCharArray();
try {
for (int i = cha.length; i >0; i--)
{
char s=cha[i-1];
String shuzi = Character.toString(s);
int count = Integer.parseInt(shuzi);
newshuzi[17-i] = count;

}
} catch (NumberFormatException ex)
{
System.out.print(ex.getMessage());
}
int ss[] = new int[] {2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9,
7};
int sh[] = new int[17];
for (int i = 0; i < ss.length; i++)
{
sh[i] = newshuzi[i] * ss[i];
}
int Consd = 0;
for (int i = 0; i < 17; i++)
{
Consd += sh[i];
}
int r = Consd % 11;
String t = "";
if (r == 0) {
t = "1";
}
if (r == 1) {
t = "0";
}
if (r == 2) {
t = "x";
}
if (r == 3) {
t = "9";
}
if (r == 4) {
t = "8";
}
if (r == 5) {
t = "7";
}
if (r == 6) {
t = "6";
}
if (r == 7) {
t = "5";
}
if (r == 8) {
t = "4";
}
if (r == 9) {
t = "3";
}
if (r == 10) {
t = "2";
}

this.code_18 += t;
return this.code_18;
}
}

[此贴子已经被作者于2007-10-21 20:09:17编辑过]

地球人的缺点与恶习集一身,小心感染不良恶习

TOP

发新话题