Time difference

RIAS
RIAS used Ask the Experts™
on
Find Time1 is greater than Time2 provided
example:
Dim dateday as date

Time1: 9:41
Time2: 1:00

if Time1 is greater than Time2 then add a day to the date.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Developer
Commented:
Please rephrase your question. Cause this is what you have posted (seems like I'm missing something):

Module Module1
    Sub Main(args As String())

        Dim Time1 As Date
        Dim Time2 As Date
        Dim TheDate As Date

        If DateTime.Compare(Time1, Time2) > 0 Then
            TheDate = TheDate.AddDays(1)
        End If

        Console.WriteLine("Done.")
        Console.ReadLine()

    End Sub
End Module

Open in new window

Author

Commented:
Thanks ste5an ,
Will try and brb
Regards

Author

Commented:
Thanks ste5an ,
Any suggestion on how to add a day to datetime field
Regards
ste5anSenior Developer

Commented:
Can you imagine, what I mean what I say, when writing "Please rephrase your question."?

A better description with more details. But you provided only a further question with new information, which doesn't fit into the original queston..
A field is a term which can mean a field of a class. But there is no class involved in your question. Or the second most usage would be the field class of a recordset object. Which doesn't exist neither.

But in the end it's normallay meaningless, when it really is a DateTime. Cause then it is then same as in the above sample:

whatEver.returnsDateTime = whatEver.returnsDateTime.AddDays(1)

Open in new window

Top Expert 2016

Commented:
Time doesn't have date component. A DateTime does;
    Sub Main()
        Dim Time1 As Date
        Dim Time2 As Date
        Dim TotalTime As Long
        Dim TotalHours As Integer
        Dim TotalMinutes As Integer

        Time1 = "09:45"
        Time2 = "01:00"

        If (Time1 > Time2) Then
            Time2.AddDays(1)
        End If
        TotalTime = DateDiff(DateInterval.Minute, Time2, Time1)
        TotalHours = TotalTime / 60
        TotalMinutes = TotalTime - (TotalHours * 60)
        If (TotalMinutes < 0) Then
            TotalMinutes += 60
        End If

        Console.WriteLine("Hours:" & TotalHours & ":" & TotalMinutes)
        ''Console.WriteLine("Done.")
        Console.ReadLine()

    End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial