In the date format, we refer to:
YYYY: four-digit yearMM: two-digit monthDD: two-digit day numberhh: two-digit hoursmm: two-digit minutesss: two-digit seconds
Important functions for working with dates:
YEAR(date): returns the year as an integer from a given date.MONTH(date): takes a date as input and returns the month as an integer from 1 to 12.CURRENT_DATE(): returns the current date in the format “YYYY-MM-DD”.CURRENT_TIMESTAMP: returns the current timestamp in the format “YYYY-MM-DD hh:mm:ss”.DATE_ADD(date, n): returns a date incremented byndays.DATE(datetime): converts a Datetime or Timestamp to Date, returning the date without the time“.TIMESTAMPDIFF(unit, datetime1, datetime2): returns the difference between two Datetime or Timestamp values in the unit specified in unit (second, minute, hour).DATEDIFF(date1, date2): returns the difference between two Date values in days.
Example
data = "2022-10-05"
YEAR(data) --ritorna 2022
DATE_ADD(data, interval 10 days) --ritorna "2022-10-15"