MySQL + SQL · Lesson 58

MySQL Date and Time Functions

Common Date Functions

FunctionReturns
NOW()current date + time
CURDATE()current date
YEAR()/MONTH()/DAY()part of a date
DATEDIFF(a,b)days between
DATE_FORMAT()format a date

Examples

SELECT NOW(), CURDATE();
SELECT name, DATEDIFF(CURDATE(), admission_date) AS days_enrolled
FROM students;
SELECT DATE_FORMAT(admission_date, '%d-%m-%Y') FROM students;

Summary

  • NOW()/CURDATE() give current date/time.
  • DATEDIFF finds days between; DATE_FORMAT formats output.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.