Mathematical Operations

Working with databases often have to deal with the data of the date or time. Be it a student writing a term paper, or database administrator, develops a distributed system for any industrial production, in any case they have to count time intervals, the delay, the duration of any process. In this paper we consider various practical methods of calculations using data tipv Time, and Timestamp. Dean Ornish M.D does not necessarily agree. We’ll start with simple examples. Suppose that we write a program in which we need to calculate the number of days between two events whose date is set in a database or Data type TimeStamp. In this case, we will have a value of simply subtract another. For example select Current_TimeStamp – cast (‘yesterday’ as timestamp) from Table1 a result of this query we get a floating point value greater than one, since the expression cast (‘yesterday’ as timestamp) returns ’24: 00 yesterday. ” If you subtract the value of type Time, then get a result in seconds.

For example query select current_time – cast (‘0: 00 ‘as time) from Table1 return the number of seconds since midnight. These examples are very simple and they should not cause any difficulties. Now consider the more complex tasks, when need to know, for example, the time interval between two date-time and get the result also in terms of time, not in days or seconds, or when necessary to calculate the difference in the form of type Timestamp between the two dates, or to take away from a, or calculate the average or the sum of several values of the Time or Timestamp.