Two the dates the difference in any specific unit that we wish - hours, seconds, minutes,Īnd so on. (Plus, the DateTime data type is only accurate to a 1/300th of a secondĪnyway, not a true millisecond.) A handy function, DateDiff(), can return for any Typically, for durations that spans hours, seconds are as accurate as you need toīe. Also, howĪccurate do we need to be - can we round to the nearest hour, or minute, or second?Īnd what happens if our total durations spans more than 24 hours - do we break "duration" doesn't clearly indicate what is needed, it is too general. Or a string in some specific format (hopefully not!), or something else? The term Offset from a certain value, or several integers indicating Hours/Minutes/Seconds, What do we mean by "duration"? What type of data, specifically,ĭo we need to return? A integer representing the total number of minutes, or a DateTime Golang compare durations code#We'd also like to ultimately return the total duration of all of the events combined.Īs always, the first step has nothing to do with writing code - it is clarifying Let us suppose that we need to calculate, for each Event, the duration of that event. This is just a simple table of Events that have both a start and an end DateTime. I will use the following table in my examples, if you'd like to play along at home: We have when storing, working with and returning this kind of data. Let's take some time to examine some options The concept of durations and TimeSpans in SQL causes lots of confusion for beginnersĪnd experienced programmers alike.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |