CURRENT_TIME Examples – MySQL

In MySQL, the CURRENT_TIME function can be used to return the current time.

This function is actually a synonym for CURTIME() which returns the current time, so you can choose which function you prefer to use.

Both functions return the current time as a value in ‘HH:MM:SS’ or HHMMSS format, depending on whether the function is used in a string or numeric context.

Continue reading

CURRENT_DATE Examples – MySQL

In MySQL, the CURRENT_DATE function can be used to return the current date.

Actually, this function is a synonym for CURDATE() which returns the current date (so you can choose which one you prefer).

Both functions return the current date as a value in ‘YYYY-MM-DD’ or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

Continue reading

ADDDATE() vs DATE_ADD() in MySQL: What’s the Difference?

When using MySQL, we have the option of using the ADDDATE() and DATE_ADD() functions whenever we want to add a specific time interval to a given date. Both these functions do the same thing, but there is one difference between them.

This article demonstrates the difference between ADDDATE() and DATE_ADD() in MySQL.

Continue reading

SUBDATE() Examples – MySQL

In MySQL, you can use the SUBDATE() function to subtract a specified amount of time from a date. For example, you could use it to subtract 10 days from a given date. You can specify whether to subtract days, weeks, months, quarters, years, etc. You can also subtract a time value, such as seconds, microseconds, etc.

When using the first syntax listed below, the SUBDATE() function is a synonym for the DATE_SUB() function (similar to how ADDDATE() is a synonym for DATE_ADD() when using the same syntax).

Continue reading

DATE_SUB() Examples – MySQL

In MySQL, you can use the DATE_SUB() function to subtract a specified amount of time from a date. For example, you can use it to subtract 7 days from a given date. You can specify whether to subtract days, weeks, months, quarters, years, etc. You can also subtract a time value, such as seconds, microseconds, etc.

This function is similar to DATE_ADD(), except that it subtracts from a date instead of adds to it.

Continue reading