From cd59503e5a65c5ccecbc2255119551c6cd6b3faa Mon Sep 17 00:00:00 2001 From: K5qu4r3d Date: Wed, 21 Jan 2026 12:18:55 -0500 Subject: [PATCH 1/4] Create term entry file --- .../concepts/dates/terms/current-timestamp/current-timestamp.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md diff --git a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md new file mode 100644 index 00000000000..e69de29bb2d From 372f900690e4e81daf4ec9cc5ae6c9202a732969 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 21 Jan 2026 15:51:27 -0500 Subject: [PATCH 2/4] Add content to new term entry --- .../current-timestamp/current-timestamp.md | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md index e69de29bb2d..bd1d7c5d569 100644 --- a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md +++ b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md @@ -0,0 +1,100 @@ +--- +Title: 'CURRENT_TIMESTAMP()' +Description: 'Get the current date and time.' +Subjects: + - 'Data Science' +Tags: + - 'Database' + - 'Queries' + - 'MySQL' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +The **`CURRENT_TIMESTAMP()`** function returns the current date and time in the string format `YYYY-MM-DD HH:MM:SS`. + +## Syntax + +```pseudo +CURRENT_TIMESTAMP([precision]) +``` + +The optional `precision` parameter specifies the desired number digits after the decimal. + +> Note: +> +> > - This function works the same as `NOW([precision])`. +> > - This syntax is specific to MySQL. A variant for Oracle SQL and SQL Server exists under `CURRENT_TIMESTAMP` without the bracket pair `()`. + +## Example 1 - String Format + +```sql +SELECT CURRENT_TIMESTAMP(); +``` + +```shell +2026-01-21 19:39:23 +``` + +## Example 2 - Numeric Format + +If `CURRENT_TIMESTAMP()` is used in a numerical context, i.e. in an arithmetic calculation, then it will return a numeric value in the format `YYYYMMDDHHMMSS`. + +```sql +-- Return with 2 decimal digits +SELECT CURRENT_TIMESTAMP() + 67; +``` + +```shell +20260121203123.56 +``` + +## Example 3 - Precision + +The optional parameter `precision` accepts an `INT` value between 0 and 6. If `precision` is between 1 and 6, then the value returned will have a fractional portion where `precision` is the number of digits after the decimal point. + +If `CURRENT_TIMESTAMP()` is used alone, then the string format returned will be in the form `YYYY-MM-DD HH:MM:SS.dddddd`. + +```sql +-- Ask for 3 decimal digits +SELECT CURRENT_TIMESTAMP(3); +``` + +```shell +2026-01-21 20:38:29.584 +``` + +If `CURRENT_TIMESTAMP()` is used in a numerical calculation, then the value returned will be in the format `YYYYMMDDHHMMSS.dddddd`. + +```sql +-- Ask for 3 decimal digits and add a value to the function +SELECT CURRENT_TIMESTAMP(3) + 67; +``` + +```shell +20260121203896.586 +``` + +If `precision` is 0, then the decimal portion is omitted. + +```sql +-- Ask for no decimal digits +SELECT CURRENT_TIMESTAMP(0); +SELECT CURRENT_TIMESTAMP(0) + 67; +``` + +```shell +2026-01-21 20:39:37 +20260121204004 +``` + +## Codebyte Example + +Run the lines below to see the function in action. + +```codebyte/sql +SELECT CURRENT_TIMESTAMP(); +SELECT CURRENT_TIMESTAMP(6); +SELECT CURRENT_TIMESTAMP(6) + 67; +``` From 1ff4d2758bd45b0d3391044209e579d6d80c497c Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 21 Jan 2026 15:52:36 -0500 Subject: [PATCH 3/4] Fix blockquote --- .../dates/terms/current-timestamp/current-timestamp.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md index bd1d7c5d569..0fbb34f4589 100644 --- a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md +++ b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md @@ -24,8 +24,8 @@ The optional `precision` parameter specifies the desired number digits after the > Note: > -> > - This function works the same as `NOW([precision])`. -> > - This syntax is specific to MySQL. A variant for Oracle SQL and SQL Server exists under `CURRENT_TIMESTAMP` without the bracket pair `()`. +> - This function works the same as `NOW([precision])`. +> - This syntax is specific to MySQL. A variant for Oracle SQL and SQL Server exists under `CURRENT_TIMESTAMP` without the bracket pair `()`. ## Example 1 - String Format From 713eaa776abec542eafb46ff4a0e1c30227a7d40 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Thu, 22 Jan 2026 17:20:29 +0530 Subject: [PATCH 4/4] Revise CURRENT_TIMESTAMP documentation and examples Updated the CURRENT_TIMESTAMP documentation to clarify usage and remove parentheses. Enhanced examples and formatting for better readability. --- .../current-timestamp/current-timestamp.md | 97 ++++++++----------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md index 0fbb34f4589..f6a8b36aaec 100644 --- a/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md +++ b/content/sql/concepts/dates/terms/current-timestamp/current-timestamp.md @@ -1,7 +1,8 @@ --- -Title: 'CURRENT_TIMESTAMP()' -Description: 'Get the current date and time.' +Title: 'CURRENT_TIMESTAMP' +Description: 'Returns the current date and time.' Subjects: + - 'Computer Science' - 'Data Science' Tags: - 'Database' @@ -12,89 +13,77 @@ CatalogContent: - 'paths/analyze-data-with-sql' --- -The **`CURRENT_TIMESTAMP()`** function returns the current date and time in the string format `YYYY-MM-DD HH:MM:SS`. +The **`CURRENT_TIMESTAMP`** function returns the current date and time in the string format `YYYY-MM-DD HH:MM:SS`. ## Syntax ```pseudo -CURRENT_TIMESTAMP([precision]) +CURRENT_TIMESTAMP ``` -The optional `precision` parameter specifies the desired number digits after the decimal. +**Parameters:** -> Note: -> -> - This function works the same as `NOW([precision])`. -> - This syntax is specific to MySQL. A variant for Oracle SQL and SQL Server exists under `CURRENT_TIMESTAMP` without the bracket pair `()`. +`CURRENT_TIMESTAMP` does not accept any parameters in standard SQL implementations. -## Example 1 - String Format +**Return value:** -```sql -SELECT CURRENT_TIMESTAMP(); -``` - -```shell -2026-01-21 19:39:23 -``` +Returns the current date and time as a `DATETIME` value (in SQL Server) or `TIMESTAMP` value (in other systems) in the format `YYYY-MM-DD HH:MM:SS.mmm`. -## Example 2 - Numeric Format +## Example 1: Basic Usage -If `CURRENT_TIMESTAMP()` is used in a numerical context, i.e. in an arithmetic calculation, then it will return a numeric value in the format `YYYYMMDDHHMMSS`. +In this example, `CURRENT_TIMESTAMP` retrieves the current date and time from the database server: ```sql --- Return with 2 decimal digits -SELECT CURRENT_TIMESTAMP() + 67; +SELECT CURRENT_TIMESTAMP; ``` +A possible output of this code is: + ```shell -20260121203123.56 +2026-01-21 19:39:23 ``` -## Example 3 - Precision - -The optional parameter `precision` accepts an `INT` value between 0 and 6. If `precision` is between 1 and 6, then the value returned will have a fractional portion where `precision` is the number of digits after the decimal point. +## Example 2: Using as Default Value -If `CURRENT_TIMESTAMP()` is used alone, then the string format returned will be in the form `YYYY-MM-DD HH:MM:SS.dddddd`. +In this example, `CURRENT_TIMESTAMP` is used as a default value for the `order_date` column, automatically capturing the timestamp when a new record is inserted: ```sql --- Ask for 3 decimal digits -SELECT CURRENT_TIMESTAMP(3); -``` +CREATE TABLE orders ( + order_id INT PRIMARY KEY, + order_date DATETIME DEFAULT CURRENT_TIMESTAMP, + product_name VARCHAR(100) +); -```shell -2026-01-21 20:38:29.584 -``` - -If `CURRENT_TIMESTAMP()` is used in a numerical calculation, then the value returned will be in the format `YYYYMMDDHHMMSS.dddddd`. +INSERT INTO orders (order_id, product_name) +VALUES (1, 'Laptop'); -```sql --- Ask for 3 decimal digits and add a value to the function -SELECT CURRENT_TIMESTAMP(3) + 67; +SELECT * FROM orders; ``` +The output shows that the `order_date` was automatically populated: + ```shell -20260121203896.586 +order_id order_date product_name +----------- ----------------------- ---------------------------------------------------------------------------------------------------- + 1 2026-01-22 11:43:29.737 Laptop ``` -If `precision` is 0, then the decimal portion is omitted. +## Example 3: Comparing Timestamps -```sql --- Ask for no decimal digits -SELECT CURRENT_TIMESTAMP(0); -SELECT CURRENT_TIMESTAMP(0) + 67; -``` +In this example, `CURRENT_TIMESTAMP` is used with [`DATEDIFF()`](https://www.codecademy.com/resources/docs/sql/dates/datediff) to calculate how many minutes have elapsed since an order was placed: -```shell -2026-01-21 20:39:37 -20260121204004 +```sql +SELECT + order_id, + product_name, + DATEDIFF(minute, order_date, CURRENT_TIMESTAMP) AS minutes_ago +FROM orders; ``` -## Codebyte Example +The output of this code is: -Run the lines below to see the function in action. - -```codebyte/sql -SELECT CURRENT_TIMESTAMP(); -SELECT CURRENT_TIMESTAMP(6); -SELECT CURRENT_TIMESTAMP(6) + 67; +```shell +order_id | product_name | minutes_ago +---------|--------------|------------ +1 | Laptop | 120 ```