From f94a7cd1fb3528c69b679e690df0de0ec78d63a5 Mon Sep 17 00:00:00 2001 From: Stuart Mosquera Date: Thu, 22 Jan 2026 14:55:27 -0300 Subject: [PATCH 1/2] Create now.md --- content/sql/concepts/dates/terms/now/now.md | 74 +++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 content/sql/concepts/dates/terms/now/now.md diff --git a/content/sql/concepts/dates/terms/now/now.md b/content/sql/concepts/dates/terms/now/now.md new file mode 100644 index 00000000000..ed723b7a42b --- /dev/null +++ b/content/sql/concepts/dates/terms/now/now.md @@ -0,0 +1,74 @@ +--- +Title: 'NOW()' +Description: 'Returns the current date and time.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Functions' + - 'MySQL' + - 'PostgreSQL' + - 'SQL' +CatalogContent: + - 'learn-sql' + - 'paths/analize-data-with-sql' +--- + +The **`NOW()`** function returns the current date and time in timestamp format. + +> **Note:** In other RDBMS like Microsoft SQL Server or SQLite, the function name or syntax may have slight variations. + +## Syntax + +```pseudo +NOW() +``` + +**Parameters:** + +The `NOW()` function does not take any parameters. + +**Return value:** + +Returns the current date and time. + +## Example 1 + +In this example, the current date and time is returned using the `NOW()` function: + +```sql +SELECT NOW() as current_timestamp; +``` + +The [`AS`](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column `current_timestamp` in the output: + +| current_timestamp | +| ------------------- | +| 2026-01-20 21:38:45 | + +## Example 2 + +In this example, the following data is given in the `users` table: + +| id | username | email | created_at | +| --- | -------- | ----------------- | ------------------- | +| 1 | jdoe | john@example.com | 2026-01-10 10:00:00 | +| 2 | asmith | alice@example.com | 2026-01-15 14:20:00 | + +The `NOW()` function is used to capture the exact moment a new account is created in the users table. + +```sql +INSERT INTO users (id, username, email, created_at) +VALUES (3, 'emiller', 'ethan@example.com', NOW()); +``` + +The following query verifies the new user created: + +```sql +SELECT * FROM users +WHERE username = 'emiller'; +``` + +| id | username | email | created_at | +| --- | -------- | ----------------- | ------------------- | +| 3 | emiller | ethan@example.com | 2026-01-22 14:29:45 | From ec8772a9b612b6007da28031546144538823ff32 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 26 Jan 2026 15:28:13 +0530 Subject: [PATCH 2/2] Fix column alias in NOW() function example Updated the SQL example to use 'now_time' instead of 'current_timestamp' for clarity. --- content/sql/concepts/dates/terms/now/now.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/sql/concepts/dates/terms/now/now.md b/content/sql/concepts/dates/terms/now/now.md index ed723b7a42b..8470c46f8ab 100644 --- a/content/sql/concepts/dates/terms/now/now.md +++ b/content/sql/concepts/dates/terms/now/now.md @@ -11,7 +11,7 @@ Tags: - 'SQL' CatalogContent: - 'learn-sql' - - 'paths/analize-data-with-sql' + - 'paths/analyze-data-with-sql' --- The **`NOW()`** function returns the current date and time in timestamp format. @@ -37,12 +37,12 @@ Returns the current date and time. In this example, the current date and time is returned using the `NOW()` function: ```sql -SELECT NOW() as current_timestamp; +SELECT NOW() AS now_time; ``` -The [`AS`](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column `current_timestamp` in the output: +The [`AS`](https://www.codecademy.com/resources/docs/sql/commands/as) keyword is used to name the resulting column `now_time` in the output: -| current_timestamp | +| now_time | | ------------------- | | 2026-01-20 21:38:45 | @@ -69,6 +69,8 @@ SELECT * FROM users WHERE username = 'emiller'; ``` +The output will be: + | id | username | email | created_at | | --- | -------- | ----------------- | ------------------- | | 3 | emiller | ethan@example.com | 2026-01-22 14:29:45 |