กระทู้เก่าบอร์ด อ.Yeadram
1,383 4
URL.หัวข้อ /
URL
การคำนวณอายุ
อยากได้การคำนวณอายุโดยแยกเป็น Field กี่วัน , กี่เดือน , กี่ปี
4 Reply in this Topic. Dispaly 1 pages and you are on page number 1
2 @R14923
จริงๆอยากให้ค้นหาคำว่า อายุ ในกระทู้เก่าดูก่อน เพราะมีการเขียนไว้เยอะแล้ว เช่น http://www.thai-access.com/suphap.php?topic_id=1511
3 @R14924
แก้ไขตรงคำนวนเดือนเป็นตามนี้ครับ
If Month(DATE) < Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
ElseIf Month(DATE) = Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
Else
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (Month(DATE) - Month(Me.BIRTH_DATE)) - 1
Else
Me.NUM = (Month(DATE) - Month(Me.BIRTH_DATE))
End If
End If
If Month(DATE) < Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
ElseIf Month(DATE) = Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.NUM = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
Else
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.NUM = (Month(DATE) - Month(Me.BIRTH_DATE)) - 1
Else
Me.NUM = (Month(DATE) - Month(Me.BIRTH_DATE))
End If
End If
4 @R14925
หนะยังผิดได้อีก แก้ไขอีกทีเฉพาะตรงคำนวนเดือน
If Month(DATE) < Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
ElseIf Month(DATE) = Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
Else
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE)) - 1
Else
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE))
End If
End If
If Month(DATE) < Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
ElseIf Month(DATE) = Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
Else
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE)) - 1
Else
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE))
End If
End If
Time: 0.3747s
'คำนวนปี
If (Month(DATE) = Month(Me.BIRTH_DATE) And Day(Me.BIRTH_DATE) < Day(DATE)) Or (Month(DATE) < Month(Me.BIRTH_DATE)) Then
Me.text_y = DateDiff("yyyy", [BIRTH_DATE], DATE) - 1
Else
Me.text_y = DateDiff("yyyy", [BIRTH_DATE], DATE)
End If
'คำนวนเดือน
If Month(DATE) < Month(Me.BIRTH_DATE) Then
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE) - 1
Else
Me.text_m = (12 - Month(Me.BIRTH_DATE)) + Month(DATE)
End If
Else
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE)) - 1
Else
Me.text_m = (Month(DATE) - Month(Me.BIRTH_DATE))
End If
End If
'คำนวนวัน
If Day(DATE) < Day(Me.BIRTH_DATE) Then
Me.text_d = (Day(DateSerial(Year(DATE), Month(DATE), 0)) - Day(Me.BIRTH_DATE)) + Day(DATE)
Else
Me.text_d = Day(DATE) - Day(Me.BIRTH_DATE)
End If