使用t-sql从身份证号中提取生日,以下是转换15位身份证号的例子,仅供参考。
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,2as 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,2as datetime)
    
return @birthday
end
GO
declare @id char(15)
set @id = '510106830328511';
print dbo.getDateFromID(@id)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2021-11-17
猜你喜欢
  • 2022-01-20
  • 2021-05-16
  • 2022-02-26
  • 2022-02-09
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案