
But if we use it with the + operator, then it will be subtracted from the input date/time. If we use a negative value with the - operator, then the specified number of minutes will be added to the input date/time. It’s possible to perform date arithmetic with negative values. If the minutes to be subtracted are in 60 minute increments, we can alternatively use hours: SELECT time '15:45' - interval '1 hour' Again, to convert seconds to days, we will divide the numerator by the number of seconds in a day (24 hours 60 minutes 60 seconds 86400). We can alternatively subtract the equivalent number in seconds: SELECT time '15:45' - interval '120 seconds' The formula remains the same except for the denominator in the bracket: A2 - (seconds to be subtracted / 86400) //where A2 contains the DateTime. We can also add a date and time value together, and subtract minutes from that: SELECT date '' + time '01:00' - interval '18 minutes' We can even subtract minutes from a date value: SELECT date '' - interval '12 minutes' We can also subtract minutes from an interval: SELECT interval '5 hours' - interval '90 minutes' class datetime.date (year, month, day) ¶. January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. So to subtract one or more minutes, we can use minute or minutes: SELECT time '07:00' - interval '1 minute' Īnd in plural form: SELECT time '07:00' - interval '45 minutes' Īnd here it is with a timestamp value: SELECT timestamp ' 09:00' - interval '30 minutes' A date object represents a date (year, month and day) in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions. We can specify intervals when performing arithmetic against dates and times. We can also subtract minutes from a date value or a date and time combination. We will use the SELECT statement and aliases to make our output readable.In PostgreSQL, we can use the - operator to subtract one or more minutes from a time value.īy “time” value, this could be an actual time value, a timestamp, or an interval. In the second query, we subtract 10 days from the given date value. In the first query we subtract 15 days from the given date value. Let us see an example of SUBDATE() with the first syntax I mentioned in the syntax section. Let us kick things off with a few basic examples of MySQL SUBDATE().



