Technology Sharing

How to get the current time in MySQL

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

In MySQL, you can get the current time in the following ways:

  1. use NOW() function:

    SELECT NOW();
    
    • 1

    NOW() The function returns the current date and time in the format'YYYY-MM-DD HH:MM:SS'

  2. use CURRENT_TIMESTAMP function:

    SELECT CURRENT_TIMESTAMP;
    
    • 1

    Its effect is NOW() Same as above, returns the current date and time.

  3. use CURRENT_DATE Function to get the current date:

    SELECT CURRENT_DATE;
    
    • 1

    The return format is 'YYYY-MM-DD'

  4. use CURRENT_TIME The function gets the current time (excluding date):

    SELECT CURRENT_TIME;
    
    • 1

    The return format is 'HH:MM:SS'

These functions can be used to obtain current time information with different precisions according to your specific needs.