RAFJR
RAFJR

Reputation: 432

Go: Finding the lower time value

I'm using C# my entire life and now trying out GO. How do I find the lower time value between two time structs?

import (
        t "time"
        "fmt"
)

func findTime() {
    timeA, err := t.Parse("01022006", "08112016")
    timeB, err := t.Parse("01022006", "08152016")
    Math.Min(timeA.Ticks, timeB.Ticks) // This is C# code but I'm looking for something similar in GO
}

Upvotes: 0

Views: 107

Answers (1)

user142162
user142162

Reputation:

You can use the Time.Before method to test if a time is before another:

timeA, err := time.Parse("01022006", "08112016")
timeB, err := time.Parse("01022006", "08152016")

var min time.Time
if timeA.Before(timeB) {
    min = timeA
} else {
    min = timeB
}

Upvotes: 3

Related Questions