Namespace PCSolution.DateTime

#Region "  DATUM PRO PRACI S DATABAZI  "

    ''' <summary>
    ''' Prace s datem pro ulozeni nebo nacteni z databaze
    ''' </summary>
    ''' <remarks></remarks>
    Class DBDate

        ''' <summary>
        ''' Ulozit datum a cas pro format databaze
        ''' </summary>
        ''' <param name="d"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Function DateToDBDate(ByVal d As Date) As String

            Return d.Year & "-" & d.Month & "-" & d.Day & " " & d.Hour & ":" & d.Minute & ":" & d.Second

        End Function

        ''' <summary>
        ''' Nacteni data a casu z databaze
        ''' </summary>
        ''' <param name="d"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Function DateFromDBDate(ByVal d As String) As Date

            Dim s() As String = d.Split(" ")
            Dim sDay, sMonth, sYear, sHour, sMinute, sSecond As String
            sDay = ""
            sMonth = ""
            sYear = ""
            sHour = ""
            sMinute = ""
            sSecond = ""

            Dim x() As String
            If s(0).ToString.Contains(".") Then
                x = s(0).Split(".")
                sYear = x(2)
                sMonth = x(1)
                sDay = x(0)
            ElseIf s(0).ToString.Contains("/") Then
                x = s(0).Split("/")
                sYear = x(2)
                sMonth = x(0)
                sDay = x(1)
            End If
            Try
                x = s(1).Split(":")
                sHour = x(0)
                sMinute = x(1)
                sSecond = x(2)
            Catch
                sHour = 0
                sMinute = 0
                sSecond = 0
            End Try
            Return New Date(sYear, sMonth, sDay, sHour, sMinute, sSecond)

        End Function

    End Class

#End Region

End Namespace
