码迷,mamicode.com
首页 > 数据库 > 详细

使用t-sql从身份证号中提取生日

时间:2014-08-31 22:44:21      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   io   ar   art   div   cti   

使用t-sql从身份证号中提取生日,一下是转换16位身份证号的例子,仅供参考。

create function getDateFromID(
@id char(15)
)
returns datetime
as
begin
declare @birthPart char(6);
set @birthPart = substring(@id,7,6);
declare @year int;
set @year = cast(left(@birthPart,2) as int);
if @year < 10 
SET @year = 2000 + @year;
else
SET @year = 1900 + @year;

declare @birthday datetime;
set @birthday = cast(cast(@year as char(4)) + - 
+ substring(@birthpart,3,2) + -
+ substring(@birthpart,6,2) as datetime)
return @birthday
end
GO
declare @id char(16)
set @id = 510106830328511;
print dbo.getDateFromID(@id)

 

使用t-sql从身份证号中提取生日

标签:style   blog   color   使用   io   ar   art   div   cti   

原文地址:http://www.cnblogs.com/tonykan/p/3948234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!