Skip to content

Instantly share code, notes, and snippets.

@CodeHeight
Created May 30, 2018 19:47
Show Gist options
  • Save CodeHeight/06e52a4b7548b01aaeead0ba76eae053 to your computer and use it in GitHub Desktop.
Save CodeHeight/06e52a4b7548b01aaeead0ba76eae053 to your computer and use it in GitHub Desktop.
PL/SQL calculates current date with past date with decimal output.
(select round(round(months_between(sysdate,v_date),0)/12,1) from dual) as date_age
Public Class PatientUtil
Public Shared Function FormatAge(ByVal date_age As String) As String
Dim date_age_year As String
Dim date_age_month As String
Dim date_age_delimiter As Char = "."c
Dim substrings() As String
'First, get it:
substrings = date_age.Split(date_age_delimiter)
'Second turn decimal (2.40) into readable string (2 years 4 months)
'begin by format year:
date_age_year = substrings(0)
If date_age_year = "1" Then
date_age_year = "1 year "
ElseIf date_age_year = "0" Then
date_age_year = Nothing
Else
date_age_year = substrings(0) & " years "
End If
'next, format month
If Not substrings.Count = 1 Then
date_age_month = substrings(1)
If date_age_month.Contains("0") Then
If date_age_month = "10" Then
date_age_month = "10 months"
Else
date_age_month = substrings(1).Substring(0, 1) & " months"
End If
End If
If Not substrings(0) = "0" Then
Return date_age_year & " " & vaccine_date_age_month
Else
Return date_age_month
End If
End If
Return date_age_year
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment