Every line of 'difference in days between two dates' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.
284 func diffDays(date1, date2 time.Time) int64 { 285 return int64(date2.Sub(date1) / (24 * time.Hour)) 286 }
41 func SameDays(date1, date2 time.Time) bool { 42 if date1.Year() == date2.Year() && date1.Month() == date2.Month() && date1.Day() == date2.Day() { 43 return true 44 } 45 return false 46 }
232 func (c Carbon) SubDays(days int) Carbon { 233 return c.AddDays(-days) 234 }
34 func minDuration(d1, d2 time.Duration) time.Duration { 35 if d1 < d2 { 36 return d1 37 } 38 return d2 39 }
82 func (c Carbon) DiffInDaysWithAbs(arg ...Carbon) int64 { 83 end := c.Now() 84 if len(arg) > 0 { 85 end = arg[0] 86 } 87 return getAbsValue(c.DiffInDays(end)) 88 }
34 func (r report) days(s2 sol) int { 35 return r.sol.days(s2) 36 }
86 func (m *MockTimeChecker) Sub(dateInJST time.Time, businessDay int) (time.Time, error) { 87 return dateInJST, nil 88 }
2040 func (s *DeltaContext) Delta_date() IDelta_dateContext { 2041 var t = s.GetTypedRuleContext(reflect.TypeOf((*IDelta_dateContext)(nil)).Elem(), 0) 2042 2043 if t == nil { 2044 return nil 2045 } 2046 2047 return t.(IDelta_dateContext) 2048 }
405 func DaysBetweenIntervals(a int32, b int32) int32 { 406 a = IntervalNumber(timeutils.UTCMidnight(TimeForIntervalNumber(a))) 407 b = IntervalNumber(timeutils.UTCMidnight(TimeForIntervalNumber(b))) 408 distance := b - a 409 // This will always divide evenly since a and b are aligned on UTC midnight boundaries. 410 days := distance / verifyapi.MaxIntervalCount 411 return days 412 }
83 func Diff(a, b time.Time) (year, month, day, hour, min, sec int) { 84 if a.Location() != b.Location() { 85 b = b.In(a.Location()) 86 } 87 if a.After(b) { 88 a, b = b, a 89 } 90 var ( 91 y1, M1, d1 = a.Date() 92 y2, M2, d2 = b.Date() 93 94 h1, m1, s1 = a.Clock() 95 h2, m2, s2 = b.Clock() 96 ) 97 98 year = y2 - y1 99 month = int(M2 - M1) 100 day = d2 - d1 101 hour = h2 - h1 102 min = m2 - m1 103 sec = s2 - s1 104 105 // Normalize negative values 106 if sec < 0 { 107 sec += 60 108 min-- 109 } 110 if min < 0 { 111 min += 60 112 hour-- 113 } 114 if hour < 0 { 115 hour += 24 116 day-- 117 } 118 if day < 0 { 119 // Reference: https://stackoverflow.com/a/49170822 120 t := time.Date(y2, M2, 0, 0, 0, 0, 0, time.UTC) 121 day += t.Day() 122 month-- 123 } 124 if month < 0 { 125 month += 12 126 year-- 127 } 128 return year, month, day, hour, min, sec 129 }