Date Functions

  1. Overview
  2. MYSQL
  3. Date Functions

MySQL SUBDATE() Function

The SUBDATE() function in MySQL is used to subtract a specified time or date interval from a given date and return the resulting date. Definition and Usage Purpose: Subtracts ...

MySQL STR_TO_DATE() Function

The STR_TO_DATE() function in MySQL is used to convert a string into a date using a specified format. Definition and Usage Purpose: Converts a string into a date or datetime ...

MySQL CURRENT_TIMESTAMP() Function

The CURRENT_TIMESTAMP() function in MySQL returns the current date and time in the format YYYY-MM-DD HH:MM:SS or as a numeric value in the YYYYMMDDHHMMSS.uuuuuu format. Definiti ...

MySQL WEEK() Function

The WEEK() function in MySQL is used to extract the week number from a given date. The function returns a number representing the week of the year, which can range from 0 to 53, de ...

MySQL DAYOFMONTH() Function

The DAYOFMONTH() function in MySQL returns the day of the month for a given date or datetime value. The result is a number between 1 and 31 representing the day of the month. De ...

MySQL DATE() Function

The DATE() function in MySQL is used to extract the date part from a datetime expression, returning only the date in the format YYYY-MM-DD. Definition and Usage The DATE() fu ...

MySQL CURTIME() Function

The CURTIME() function in MySQL returns the current time in the format HH:MM:SS (string) or as a numeric value in the HHMMSS.uuuuuu format. Definition and Usage The CURTIME() ...

MySQL PERIOD_ADD() Function

The PERIOD_ADD() function is used to add a specified number of months to a given period. The result is returned in the YYYYMM format. Definition and Usage Purpose: Adds a spe ...

MySQL LOCALTIMESTAMP() Function

The LOCALTIMESTAMP() function returns the current date and time based on the system's local timezone. Definition and Usage The LOCALTIMESTAMP() function returns the current d ...

MySQL YEAR() Function

The YEAR() function in MySQL extracts the year part from a given date or datetime value. It returns the year as a four-digit number (ranging from 1000 to 9999). Definition and U ...

MySQL PERIOD_DIFF() Function

The PERIOD_DIFF() function calculates the difference in months between two periods. Both periods must be in the same format (YYMM or YYYYMM), and the result is returned as the numb ...

MySQL LAST_DAY() Function

The LAST_DAY() function is used to extract the last day of the month for a given date. Definition and Usage The LAST_DAY() function returns the last day of the month for a gi ...

MySQL DAYOFYEAR() Function

The DAYOFYEAR() function in MySQL returns the day of the year for a given date, represented as a number between 1 and 366. It is useful for determining which day of the year a spec ...

MySQL TIME_TO_SEC() Function

The TIME_TO_SEC() function in MySQL is used to convert a time value into the total number of seconds. Definition and Usage Purpose: Converts a given time value into seconds. ...

MySQL SEC_TO_TIME() Function

The SEC_TO_TIME() function in MySQL is used to convert a specified number of seconds into a time value. The result is formatted as HH:MM:SS. Definition and Usage Purpose: Con ...

MySQL FROM_DAYS() Function

The FROM_DAYS() function is used to convert a numeric day value (representing the number of days since '0000-01-01') into a date value. This function is useful for working with num ...

MySQL ADDTIME() Function

The ADDTIME() function is used in MySQL to add a specific time interval to a given time or datetime and return the resulting time/datetime. Definition and Usage The ADDTIME() ...

MySQL DATE_SUB() Function

The DATE_SUB() function in MySQL is used to subtract a time/date interval from a given date and return the result. This is useful when you need to compute a date that is a certain ...

MySQL EXTRACT() Function

The EXTRACT() function in MySQL is used to retrieve specific parts of a date or time value. It allows you to extract components such as the year, month, day, hour, minute, second, ...

MySQL HOUR() Function

The HOUR() function extracts the hour part from a given DATETIME, DATE, or TIME value. Definition and Usage The HOUR() function returns the hour part of a given date or time ...

MySQL MONTHNAME() Function

MySQL MONTHNAME() Function The MONTHNAME() function is used to extract the name of the month from a given date or datetime value. Definition and Usage Purpose: Retrieve the ...

MySQL ADDDATE() Function

The ADDDATE() function in MySQL is used to add a specific time/date interval to a given date and return the resulting date. Definition and Usage The ADDDATE() function allows ...

MySQL TIMESTAMP() Function

The TIMESTAMP() function in MySQL is used to return a datetime value based on a specified date (and optionally a time) value. Definition and Usage Purpose: The function combi ...

MySQL DAYNAME() Function

The DAYNAME() function in MySQL returns the full name of the weekday for a given date or datetime value. The result is the name of the weekday (e.g., "Monday", "Tuesday", etc.). ...

MySQL SUBTIME() Function

The SUBTIME() function in MySQL is used to subtract a specified time interval from a given time or datetime value. It returns the resulting time or datetime after the subtraction. ...

MySQL YEARWEEK() Function

The YEARWEEK() function in MySQL returns the year and week number (a number from 0 to 53) for a given date or datetime. It combines the year and week number into a single number, w ...

MySQL DATE_FORMAT() Function

The DATE_FORMAT() function in MySQL is used to format a date or datetime value according to a specified format. This allows you to present the date in a customized way, for example ...

MySQL TIME_FORMAT() Function

The TIME_FORMAT() function in MySQL is used to format a given time expression according to a specific format. It allows you to display time values in various ways by using format s ...

MySQL DATEDIFF() Function

The DATEDIFF() function in MySQL calculates the number of days between two date values. It subtracts the second date (date2) from the first (date1) and returns the difference in te ...

MySQL MAKEDATE() Function

The MAKEDATE() function creates and returns a date based on a specified year and a number representing the day of the year. Definition and Usage Purpose: To generate a date u ...

MySQL MAKETIME() Function

The MAKETIME() function creates and returns a TIME value based on the specified hour, minute, and second values. Definition and Usage The function takes hour, minute, and ...

MySQL SECOND() Function

The SECOND() function in MySQL is used to return the seconds part from a given time or datetime value. The result will be a number between 0 and 59. Definition and Usage Purp ...

MySQL MONTH() Function

The MONTH() function is used to extract the month part from a given date or datetime value. Definition and Usage Purpose: Extract the month component from a date or datetime ...

MySQL DAYOFWEEK() Function

The DAYOFWEEK() function in MySQL returns the weekday index for a given date, where the result is a number between 1 and 7. This index corresponds to the days of the week, starting ...

MySQL CURDATE() Function

The CURDATE() function in MySQL returns the current date. It is useful for retrieving today's date in your queries. Definition and Usage The CURDATE() function returns the cu ...

MySQL TO_DAYS() Function

The TO_DAYS() function in MySQL is used to return the number of days between a given date and the "zero" date, which is defined as the start of the Gregorian calendar, i.e., 0000-0 ...

MySQL DATE_ADD() Function

The DATE_ADD() function in MySQL is used to add a specified time/date interval to a date and return the new date. It is commonly used for date arithmetic operations such as adding ...

MySQL MICROSECOND() Function

The MICROSECOND() function extracts and returns the microsecond part of a time or datetime value as an integer (ranging from 0 to 999999). Definition and Usage This function ...

MySQL CURRENT_DATE() Function

The CURRENT_DATE() function in MySQL returns the current date. This function is equivalent to the CURDATE() function. Definition and Usage The CURRENT_DATE() function returns ...

MySQL WEEKDAY() Function

The WEEKDAY() function in MySQL is used to return the weekday number for a given date. It assigns a numerical value to each day of the week, with Monday being 0 and Sunday being 6. ...

MySQL MINUTE() Function

The MINUTE() function is used to extract the minute part from a given time or datetime value. Definition and Usage Purpose: To extract the minute component of a time/datetime ...

MySQL NOW() Function

The NOW() function retrieves the current date and time from the server. It is commonly used in queries to log timestamps or compare data with the current datetime. Definition an ...

MySQL QUARTER() Function

The QUARTER() function is used to return the quarter of the year for a given date. The result will be an integer value from 1 to 4, depending on the month of the provided date. ...

MySQL WEEKOFYEAR() Function

The WEEKOFYEAR() function in MySQL is used to return the week number for a given date, where the first week of the year is determined as the one that contains the first Thursday of ...

MySQL TIME() Function

The TIME() function in MySQL is used to extract the time part from a given time or datetime expression. This function is useful when you want to discard the date portion of a datet ...

MySQL CURRENT_TIME() Function

The CURRENT_TIME() function in MySQL returns the current time in the format HH:MM:SS or as a numeric value in the HHMMSS.uuuuuu format. Definition and Usage The CURRENT_TIME( ...

MySQL SYSDATE() Function

The SYSDATE() function in MySQL is used to return the current date and time at the moment the function is executed. Unlike NOW(), which returns the time when the query starts execu ...

MySQL DAY() Function

The DAY() function in MySQL is used to return the day of the month from a given date or datetime value. The result is an integer between 1 and 31, representing the day of the month ...

MySQL TIMEDIFF() Function

The TIMEDIFF() function in MySQL is used to return the difference between two time or datetime expressions. Definition and Usage Purpose: The function calculates the differen ...

MySQL LOCALTIME() Function

The LOCALTIME() function is used to return the current date and time in the system's local timezone. Definition and Usage The LOCALTIME() function returns the current date an ...