← Back to MySQL Course | Chapter 13: Date & Numeric Functions | Lesson 3 of 6

NOW CURDATE CURTIME

NOW, CURDATE और CURTIME एक clock और एक calendar से पूछने जैसे हैं: date और time साथ, सिर्फ आज की date, या सिर्फ time।
Syntax
sql
NOW()
CURDATE()
CURTIME()

NOW के साथ Current Date और Time

NOW current date और time दोनों को second तक एक single value की तरह साथ return करता है, इसे किसी row insert होने या event होने का exactly time stamp करने का go-to function बनाते हुए।

उदाहरण: The Current Date and Time with NOW

sql
SELECT NOW() AS current_datetime;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

CURDATE के साथ Current Date

CURDATE बिना किसी time component के सिर्फ आज की date return करता है, जो सही choice है जब आपको परवाह हो कि कुछ किस दिन हुआ लेकिन exact hour या minute irrelevant हो, जैसे एक billing date।

उदाहरण: The Current Date with CURDATE

sql
SELECT CURDATE() AS today;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

CURTIME के साथ Current Time

CURTIME बिना कोई date attached किए सिर्फ current time return करता है, daily opening/closing hours जैसी चीज़ें log करने या एक specific calendar day के बजाय एक recurring daily schedule से compare करने के लिए उपयोगी।

उदाहरण: The Current Time with CURTIME

sql
SELECT CURTIME() AS right_now;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Tables में Current Dates Save करना

ये functions आमतौर पर default column values की तरह wire up किए जाते हैं, इसलिए MySQL automatically नई rows को उनके बनने के moment से stamp कर देता है बिना application को खुद एक timestamp calculate और भेजने की ज़रूरत के।

उदाहरण: Saving Current Dates to Tables

sql
CREATE TABLE logs (id INT, message TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP);
INSERT INTO logs (id, message) VALUES (1, 'User signed up');
SELECT * FROM logs;

Intervals के साथ Simple Date Math

आप current date के against सीधे intervals add या subtract कर सकते हैं, जैसे CURDATE() + INTERVAL 7 DAY, application code में manual date arithmetic के बिना एक one-week deadline या trial expiration जैसी चीज़ें compute करने के लिए।

उदाहरण: Simple Date Math with Intervals

sql
SELECT CURDATE() + INTERVAL 7 DAY AS trial_expires;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. सिर्फ date चाहिए होने पर NOW() इस्तेमाल करना, ताकि एक DATE column से comparisons time part पर fail हो जाएँ।
  2. यह मान लेना कि NOW() एक query के दौरान बदलता है, जबकि यह statement की शुरुआत में fixed है (real time के लिए SYSDATE() इस्तेमाल करें)।
  3. server की time zone भूल जाना जब output आपके local time से अलग हो।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.