Public Class MyDate

    Public Shared Function DIFF_Time(ByVal sd As Date, ByVal ed As Date) As Short
        '//두날짜사이의 차리르 분으로 환상한다.
        Dim sdt As Short = sd.Hour * 60 + sd.Minute
        Dim edt As Short = ed.Hour * 60 + ed.Minute
        Return edt - sdt
    End Function
    Public Shared Function DIFF_TimeC(ByVal sd As Date, ByVal ed As Date) As String
        '//두날짜사이의 차리르 분으로 환상한다.
        Dim sdt As Short = sd.Hour * 60 + sd.Minute
        Dim edt As Short = ed.Hour * 60 + ed.Minute
        Return TimeChar(edt - sdt)
    End Function
    Public Shared Function TimeChar(ByVal Min As Short) As String
        Dim Retval As String = Math.Truncate(Min / 60)
        Dim Retval2 As String = Min Mod 60
        Return Retval & ":" & Retval2
    End Function
    Public Shared Function LastDay(ByVal Cd As Date) As Date
        '//말일자를 반환
        Dim Nd As Date = CDate(Format(Cd.AddMonths(1), "yyyy-MM-01")).AddDays(-1)
        Return Nd
    End Function
    Public Shared Function FirstDay(ByVal Cd As Date) As Date
        '//말일자를 반환
        Dim Nd As Date = CDate(Format(Cd, "yyyy-MM-01"))
        Return Nd
    End Function

    Public Shared Function FirstWeek(ByVal cd As Date) As Date
        Return cd.AddDays(1 - cd.DayOfWeek)
    End Function

    Public Shared Function LastWeek(ByVal cd As Date) As Date
        Return cd.AddDays(7 - cd.DayOfWeek)
    End Function
    Public Shared Function GetWeekName(ByVal Cd As Date) As String
        Select Case Cd.DayOfWeek
            Case DayOfWeek.Friday
                Return "금"
            Case DayOfWeek.Monday
                Return "월"
            Case DayOfWeek.Saturday
                Return "토"
            Case DayOfWeek.Sunday
                Return "일"
            Case DayOfWeek.Thursday
                Return "목"
            Case DayOfWeek.Tuesday
                Return "화"
            Case DayOfWeek.Wednesday
                Return "수"
        End Select
        Return Cd.DayOfWeek
    End Function
    Public Shared Function GetFullDateText(ByVal src As String) As String
        Select Case src.Length
            Case 10
                Return src
            Case 8 '//20090501
                Return src.Substring(0, 4) & "-" & src.Substring(4, 2) & "-" & src.Substring(6, 2)
            Case 6 '//090501
                Return "20" & src.Substring(0, 2) & "-" & src.Substring(2, 2) & "-" & src.Substring(4, 2)
            Case 4 '//0501
                Return Format(Today, "yyyy") & "-" & src.Substring(0, 2) & "-" & src.Substring(2, 2)
            Case 3 '//501
                Return Format(Today, "yyyy") & "-" & "0" & src.Substring(0, 1) & "-" & src.Substring(1, 2)
            Case 2 '//01
                Return Format(Today, "yyyy-MM") & "-" & src.Substring(0, 2)
            Case 1 '//1
                Return Format(Today, "yyyy-MM") & "-0" & src.Substring(0, 1)
            Case Else
                Return ""
        End Select
    End Function
End Class
