如果出生日期輸入格式為19861212這種格式的話,以1-3月為春季,4-6月為夏季,7-9月為秋季,10-12月為冬季,用以下代碼:
目前累計服務客戶1000多家,積累了豐富的產品開發(fā)及服務經驗。以網站設計水平和技術實力,樹立企業(yè)形象,為客戶提供成都網站制作、成都做網站、網站策劃、網頁設計、網絡營銷、VI設計、網站改版、漏洞修補等服務。創(chuàng)新互聯(lián)建站始終以務實、誠信為根本,不斷創(chuàng)新和提高建站品質,通過對領先技術的掌握、對創(chuàng)意設計的研究、對客戶形象的視覺傳遞、對應用系統(tǒng)的結合,為客戶提供更好的一站式互聯(lián)網解決方案,攜手廣大客戶,共同發(fā)展進步。
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("請輸入您的生日,格式為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
'計算年齡,幾歲幾個月幾天,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
'還差一個月才到一年
year = year - 1
ElseIf till.Month birth.Month Then
'超過一個月
ElseIf till.Month = birth.Month Then
'同一個月
If till.Day birth.Day Then
'從天數看還沒到一個月,不操作
year = year - 1
ElseIf till.Day = birth.Day Then
'到了天數,或超了天數
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
'從天數看還沒到一個月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天數,或超了天數,不操作
End If
ElseIf month = 0 Then
''同一個月
If till.Day birth.Day Then
'從天數看,已經超過了今天的日期,而且肯定不是同一年
month = 11
ElseIf till.Day = birth.Day Then
'到了天數,或超了天數,同一個月,還沒過生日
End If
ElseIf month 0 Then
If till.Day birth.Day Then
'從天數看還沒到一個月,不操作
month = month - 1
ElseIf till.Day = birth.Day Then
'到了天數,或超了天數,不操作
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個
i=year(now())-val(y)+1
now()函數是獲得現在的電腦的時間,year是把now的年份取出,val是把字符串轉換成數字,因為剛生下來就是1歲所以要加1
msgbox i
Private Sub Command1_Click()
If IsDate(Text1) = False Then
MsgBox "輸入時間錯誤!"
Exit Sub
End If
Text2 = Round(DateDiff("m", Text1, Now) / 12, 1) "歲"
End Sub
Public Class 主窗體
Dim 身份證號碼 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 身份證號碼輸入框.TextLength = 15 Then
身份證號碼 = 身份證號碼輸入框.Text
生日年份 = "19" 身份證號碼.Substring(6, 2)
生日月份 = 身份證號碼.Substring(8, 2)
生日日期 = 身份證號碼.Substring(10, 2)
ElseIf 身份證號碼輸入框.TextLength = 18
身份證號碼 = 身份證號碼輸入框.Text
生日年份 = 身份證號碼.Substring(6, 4)
生日月份 = 身份證號碼.Substring(10, 2)
生日日期 = 身份證號碼.Substring(12, 2)
Else
MsgBox("請輸入正確的身份證號碼!", MsgBoxStyle.Information, "身份證號碼有誤")
身份證號碼輸入框.SelectAll()
身份證號碼輸入框.Focus()
Exit Sub
End If
If IsNumeric(生日年份) And IsNumeric(生日月份) And IsNumeric(生日日期) Then
生日 = New Date(生日年份, 生日月份, 生日日期)
End If
生日標簽.Text = 生日.ToLongDateString
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
這是 .NET 的,有疑問請追問