如果出生日期輸入格式為19861212這種格式的話,以1-3月為春季,4-6月為夏季,7-9月為秋季,10-12月為冬季,用以下代碼:
目前累計(jì)服務(wù)客戶1000多家,積累了豐富的產(chǎn)品開發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹立企業(yè)形象,為客戶提供成都網(wǎng)站制作、成都做網(wǎng)站、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。創(chuàng)新互聯(lián)建站始終以務(wù)實(shí)、誠信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過對(duì)領(lǐng)先技術(shù)的掌握、對(duì)創(chuàng)意設(shè)計(jì)的研究、對(duì)客戶形象的視覺傳遞、對(duì)應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。
Private Sub Form_Load()
Dim birth As String
Dim year As Integer
Dim month As Integer
Dim day As String
Dim old As Integer
Dim season As String
Dim sx As Integer
Dim fx As String
birth = Trim(Str(InputBox("請(qǐng)輸入您的生日,格式為19741212")))
year = Val(Left(birth, 4))
month = Val(Mid(birth, 5, 2))
day = Right(birth, 2)
old = 2015 - year
Select Case month
Case Is = 3
season = "春季"
Case Is = 6
season = "夏季"
Case Is = 9
season = "秋季"
Case Is = 12
season = "冬季"
End Select
sx = (year - 2016) Mod 12
If sx 0 Then
sx = sx + 12
End If
Select Case sx
Case 0
fx = "猴"
Case 1
fx = "雞"
Case 2
fx = "狗"
Case 3
fx = "豬"
Case 4
fx = "鼠"
Case 5
fx = "牛"
Case 6
fx = "虎"
Case 7
fx = "兔"
Case 8
fx = "龍"
Case 9
fx = "蛇"
Case 10
fx = "馬"
Case 11
fx = "羊"
End Select
MsgBox "您的年齡為:" old vbCrLf "您的出生季節(jié)為:" season vbCrLf "您的屬相為:" fx
End Sub
我也就是閑著無聊,給這5分都不夠敲鍵盤的
Function age(ByVal till As Date, ByVal birth As Date) As String
'計(jì)算年齡,幾歲幾個(gè)月幾天,till:截止日期,birth生日
Dim year As Integer = 0 '年
year = till.Year - birth.Year
If year 0 Then
Return ""
End If
If year = 0 Then
''
End If
If year 0 Then
If till.Month birth.Month Then
'還差一個(gè)月才到一年
year = year - 1
ElseIf till.Month birth.Month Then
'超過一個(gè)月
ElseIf till.Month = birth.Month Then
'同一個(gè)月
If till.Day birth.Day Then
'從天數(shù)看還沒到一個(gè)月,不操作
year = year - 1
ElseIf till.Day = birth.Day Then
'到了天數(shù),或超了天數(shù)
End If
End If
End If
Dim month As Integer = till.Month - birth.Month
If month 0 Then
month = 12 + month
If till.Day birth.Day Then
'從天數(shù)看還沒到一個(gè)月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天數(shù),或超了天數(shù),不操作
End If
ElseIf month = 0 Then
''同一個(gè)月
If till.Day birth.Day Then
'從天數(shù)看,已經(jīng)超過了今天的日期,而且肯定不是同一年
month = 11
ElseIf till.Day = birth.Day Then
'到了天數(shù),或超了天數(shù),同一個(gè)月,還沒過生日
End If
ElseIf month 0 Then
If till.Day birth.Day Then
'從天數(shù)看還沒到一個(gè)月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天數(shù),或超了天數(shù),不操作
End If
End If
Dim day As Integer = till.Day - birth.Day
If day = 0 Then
'ok
ElseIf day 0 Then
day = Date.DaysInMonth(birth.Year, birth.Month) - birth.Day + till.Day
End If
Return year "歲" month "月" day "天"
End Function
dim s as string,y as string i as long
s=xxxxxx19920315xxxx
y=mid(s,7,4)
從身份證的第七位取4個(gè)
i=year(now())-val(y)+1
now()函數(shù)是獲得現(xiàn)在的電腦的時(shí)間,year是把now的年份取出,val是把字符串轉(zhuǎn)換成數(shù)字,因?yàn)閯偵聛砭褪?歲所以要加1
msgbox i
Private Sub Command1_Click()
If IsDate(Text1) = False Then
MsgBox "輸入時(shí)間錯(cuò)誤!"
Exit Sub
End If
Text2 = Round(DateDiff("m", Text1, Now) / 12, 1) "歲"
End Sub
Public Class 主窗體
Dim 身份證號(hào)碼 As String
Dim 生日年份 As String
Dim 生日月份 As String
Dim 生日日期 As String
Dim 生日 As Date
Private Sub 輸出生日按鈕_Click(sender As Object, e As EventArgs) Handles 輸出生日按鈕.Click
Try
If 身份證號(hào)碼輸入框.TextLength = 15 Then
身份證號(hào)碼 = 身份證號(hào)碼輸入框.Text
生日年份 = "19" 身份證號(hào)碼.Substring(6, 2)
生日月份 = 身份證號(hào)碼.Substring(8, 2)
生日日期 = 身份證號(hào)碼.Substring(10, 2)
ElseIf 身份證號(hào)碼輸入框.TextLength = 18
身份證號(hào)碼 = 身份證號(hào)碼輸入框.Text
生日年份 = 身份證號(hào)碼.Substring(6, 4)
生日月份 = 身份證號(hào)碼.Substring(10, 2)
生日日期 = 身份證號(hào)碼.Substring(12, 2)
Else
MsgBox("請(qǐng)輸入正確的身份證號(hào)碼!", MsgBoxStyle.Information, "身份證號(hào)碼有誤")
身份證號(hào)碼輸入框.SelectAll()
身份證號(hào)碼輸入框.Focus()
Exit Sub
End If
If IsNumeric(生日年份) And IsNumeric(生日月份) And IsNumeric(生日日期) Then
生日 = New Date(生日年份, 生日月份, 生日日期)
End If
生日標(biāo)簽.Text = 生日.ToLongDateString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
這是 .NET 的,有疑問請(qǐng)追問
本文名稱:vb.net生日年齡 vb計(jì)算年齡的代碼
文章地址:http://jinyejixie.com/article10/dodhsgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、App開發(fā)、企業(yè)網(wǎng)站制作、網(wǎng)站制作、網(wǎng)站營銷、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)