How to Get the Current Date and Time in SQL Server

To retrieve the current date and time in SQL Server, you can use built-in functions such as GETDATE(), SYSDATETIME(), and CURRENT_TIMESTAMP. These functions are essential for handling tasks that rely on precise timestamps, from day-to-day queries to enterprise-level workflows. They support a wide range of operational and analytical tasks across production systems, including:

  • Scheduling recurring jobs and processes.
  • Auditing user activity with precise timestamps.
  • ETL processes that depend on load or refresh times.
  • Temporal queries for filtering or comparing historical data.

This guide walks you through SQL Server’s date and time functions, showing how to retrieve, extract, convert, and format values effectively, with examples you can use right away.

SQL Server functions for the current date and time

SQL Server offers built-in functions to retrieve the current system date and time, including GETDATE(), SYSDATETIME(), and CURRENT_TIMESTAMP. While each of them returns a timestamp, they differ in precision, ANSI compliance, and portability.

In the following subsections, we’ll look at these three functions one by one. We’ll illustrate our examples using dbForge Studio for SQL Server to show how they work and when to use them.

GETDATE()

To get the current system date and time in SQL Server, use GETDATE(). This function returns a datetime value containing both the date and time from the computer where the SQL Server instance is running. The default output format is yyyy-mm-dd hh:mm:ss.

Basic syntax

SELECT GETDATE();

When executed, the function returns the current system date and time, as shown below.

GETDATE() query in dbForge Studio for SQL Server is returning the current system datetime.

Real-world use cases

  • Inserting timestamps into audit or logging tables when new rows are created.
  • Filtering data by today’s date, such as retrieving all orders placed on the current day.

Because GETDATE() is a T-SQL-specific function, it may not exist or may behave differently in other SQL dialects.

SYSDATETIME()

SYSDATETIME() returns the current date and time with higher precision than GETDATE(). It produces a datetime2(7) value with up to 100-nanosecond resolution, making it suitable for scenarios that require fine temporal granularity.

Basic syntax

SELECT SYSDATETIME();

When executed, the function returns the current system date and time with nanosecond precision, as shown below.

SYSDATETIME() query in dbForge Studio for SQL Server is showing high-precision datetime2 output.

Real-world use cases

  • Capturing high-precision event logs, such as errors or transaction timings.
  • Recording IoT sensor data or other time-sensitive streams.
  • Supporting applications where sub-millisecond accuracy matters, such as performance monitoring.

Compared to GETDATE(), which returns a datetime value with millisecond precision, SYSDATETIME() offers far more detail. This makes it a better choice for applications that demand exact time measurements rather than approximate timestamps.

CURRENT_TIMESTAMP

Wondering what CURRENT_TIMESTAMP is in SQL Server? Put simply, CURRENT_TIMESTAMP is a function that returns the current system date and time as a datetime value with millisecond precision. CURRENT_TIMESTAMP works the same as GETDATE(), but with one important distinction: it follows the ANSI SQL standard, making it portable across different database systems.

Because of its temporal portability and ANSI compliance, this function is often preferred in scenarios like:

  • Writing scripts that must run on multiple database platforms.
  • Recording timestamps in audit logs or backup operations.
  • Defining default values for timestamp columns in cross-dialect SQL.

Let's compare CURRENT_TIMESTAMP and GETDATE():

SELECT  
    GETDATE() AS GetDateOutput, 
    CURRENT_TIMESTAMP AS CurrentTimestampOutput;

When executed, both functions return the current date and time from the SQL Server system clock, as shown below.

CURRENT_TIMESTAMP and GETDATE() queries in dbForge Studio for SQL Server are showing system datetime output.

Both queries produce the same output in SQL Server, but CURRENT_TIMESTAMP ensures broader compatibility, while GETDATE() is SQL Server-specific.

Takeaway: Use CURRENT_TIMESTAMP when you want SQL code that remains portable beyond SQL Server.

Comparison of GETDATE(), SYSDATETIME() and CURRENT_TIMESTAMP

The date function you choose in SQL Server affects both precision and portability. Precision defines how much detail your timestamps capture. If the resolution is too low, event logs and transaction records can lose their true sequence. Portability, on the other hand, determines whether your SQL code works outside SQL Server. Functions tied only to T-SQL may break in other environments, while ANSI-compliant options ensure your queries remain usable across platforms.

So, which SQL Server function gives the most accurate timestamp? Among the three, SYSDATETIME() is the most precise, returning a datetime2(7) value with ~100-nanosecond resolution. GETDATE() and CURRENT_TIMESTAMP both use the older datetime type with only millisecond precision. Between these two, CURRENT_TIMESTAMP is ANSI-compliant, making it the better choice for cross-dialect compatibility.

The table below shows their differences at a glance.

Function Data return type Precision Description
GETDATE() DATETIME Milliseconds (.000, .003, .007) The most commonly used of all functions. Returns the current date and time with standard SQL Server precision. Widely used in SQL Server applications.
SYSDATETIME() DATETIME2(7) 100 nanoseconds Returns the high-precision current date and time values. Is suitable for scenarios requiring very fine time measurements, high-resolution time logging, or calculations.
CURRENT_TIMESTAMP DATETIME Milliseconds (.000, .003, .007) ANSI SQL standard equivalent of GETDATE(), offering the same precision and type. Can be used anywhere that GETDATE() is applicable, but with better portability across different SQL platforms.
Note

All three functions return the local date and time based on the operating system of the computer hosting the SQL Server instance. Connecting to a remote SQL Server instance brings the date and time values that align with the settings of the remote server's system.

Extracting specific parts of the date and time value

You might be asking yourself, “How can I isolate date or time from a datetime value in SQL Server?” Often, you don’t need the full timestamp. You may only want the date, the time, or even a specific component like the year or hour. SQL Server provides several functions to break down a datetime into its parts.

The most common approaches are:

  • CAST() – to convert a datetime into a date or time only.
  • CONVERT() – to extract date or time with more control over formatting.
  • DATEPART() – to pull out individual elements like year, month, day, or hour.
  • FORMAT() – to display the value in a custom string format.

Further, we’ll explore each method with examples.

Using CAST()

CAST() is the simplest way to reduce a datetime value to either a date or a time. It performs a type conversion without formatting options.

Example 1: Extracting the current date only

SELECT 
    CAST(GETDATE() AS DATE) AS DateOnly;

Use this when building reports that group by day, such as daily sales summaries.

Example 2: Extracting the current time only

SELECT 
    CAST(GETDATE() AS TIME) AS TimeOnly;

This approach is essential for scenarios like filtering records by business hours.

Takeaway: CAST() is best for quick truncation when you just need the raw date or time portion.

Using CONVERT()

CONVERT() also changes a datetime to another type, but it adds formatting control through style codes. This makes it more flexible for reporting or data exchange.

Example 1: Extracting the current date only

SELECT 
    CONVERT(DATE, GETDATE()) AS DateOnly;

This statement is suitable for ETL workflows where the time is irrelevant, and only the date needs to be loaded or compared.

Example 2: Extracting the current time only

SELECT 
    CONVERT(TIME, GETDATE()) AS TimeOnly;

This method is helpful when storing or comparing time values independently of the date.

Takeaway: CONVERT() does what CAST() does but gives you more control, especially when you need specific date or time formats.

Getting the current date without the time

To extract just the date part from a datetime value, you can use CAST() or CONVERT(). Both methods truncate the timestamp and return only the date portion in the yyyy-mm-dd format. This is often used in date-only formatting or when filtering queries by today’s orders.

Example 1: Using CAST()

SELECT 
    CAST(GETDATE() AS DATE) AS DateOnly;

This method is simple and effective when you need to drop the time component entirely.

Example 2: Using CONVERT()

SELECT 
    CONVERT(DATE, GETDATE()) AS DateOnly;

This offers the same result but fits naturally into workflows where CONVERT() is already used for formatting.

CAST() and CONVERT() queries in dbForge Studio for SQL Server are showing date-only output.

Both approaches remove the time portion and are useful for scenarios like “show me all sales from today” without considering hours or minutes.

Getting the current time without the date

The CAST() or CONVERT() functions can be used to retrieve only the time portion, excluding the date, in the hh:mm:ss format. The following examples illustrate how to extract the time value.

Example 1: Using CAST()

SELECT
  CAST(GETDATE() AS TIME) AS 'TimeOnly';

Example 2: Using CONVERT()

SELECT
  CONVERT(TIME, GETDATE()) AS 'TimeOnly';
CAST() and CONVERT() queries in dbForge Studio for SQL Server are showing time-only output.

Using DATEPART() and FORMAT()

Need to extract the day, month, or hour from a datetime in SQL Server? Two functions make this easy: DATEPART() for pulling out individual components, and FORMAT() for displaying a datetime value in a custom string format.

Using DATEPART() for component extraction

DATEPART() returns a specific part of a datetime value, such as year, month, day, or hour. It’s often used for filtering, grouping, or calculations.

Syntax:

SELECT 
    DATEPART(interval, date);

Parameters:

  • interval: The part of the date to return. Common options: year, quarter, month, day, week, weekday, hour, minute, second, millisecond, microsecond, nanosecond.
  • date: The datetime expression to evaluate. Accepted types: date, datetime, datetime2, smalldatetime, datetimeoffset, time.

Example 1: Extracting multiple components from a fixed datetime

SELECT
  DATEPART(year, '2026-01-15 04:16:18.060') AS 'Year'
 ,DATEPART(month, '2026-01-15 04:16:18.060') AS 'Month'
 ,DATEPART(day, '2026-01-15 04:16:18.060') AS 'Day'
 ,DATEPART(dayofyear, '2026-01-15 04:16:18.060') AS 'DayOfYear'
 ,DATEPART(weekday, '2026-01-15 04:16:18.060') AS 'WeekDay'
 ,DATEPART(hour, '2026-01-15 04:16:18.060') AS 'Hour'
 ,DATEPART(minute, '2026-01-15 04:16:18.060') AS 'Minute'
 ,DATEPART(second, '2026-01-15 04:16:18.060') AS 'Second';
DATEPART() query in dbForge Studio for SQL Server is extracting individual components from a fixed datetime.

Example 2: Extracting components from the current date using GETDATE()

SELECT
  DATEPART(year, GETDATE()) AS 'Year'
 ,DATEPART(month, GETDATE()) AS 'Month'
 ,DATEPART(day, GETDATE()) AS 'Day'
 ,DATEPART(dayofyear, GETDATE()) AS 'DayofYear'
 ,DATEPART(weekday, GETDATE()) AS 'WeekDay';
DATEPART() query in dbForge Studio for SQL Server is extracting components from the current system date.

This is useful for queries like “show me all orders from December” or “calculate how many sales happened in each hour.”

Using FORMAT() for custom display formats

FORMAT() lets you return a datetime value as a formatted string. It’s more flexible than CONVERT(), supporting custom patterns and localization.

Syntax:

SELECT 
    FORMAT(datetime_value, 'format_string');

Parameters:

  • datetime_value: The date or datetime to format.
  • format_string: A .NET-style pattern that defines the display format. Examples: dd-MMM-yyyy, yyyy-MM-dd HH:mm, MMMM dd, yyyy.

Examples: Common formatting patterns

SELECT FORMAT(GETDATE(), 'dd-MMM-yyyy')      AS ReportDate;   -- 17-Jan-2026 
SELECT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') AS LogStamp;     -- 2026-01-17 19:45 
SELECT FORMAT(GETDATE(), 'MMMM dd, yyyy')    AS FullDate;     -- January 17, 2026 

This method is ideal for reports, logs, or applications that require a specific regional or human-readable format.

Takeaway: Use DATEPART() for numeric values you want to filter or calculate with, and FORMAT() when you need a display-friendly string.

Handling time zones and UTC in SQL Server

Need to retrieve UTC time in SQL Server? By default, functions like GETDATE() and SYSDATETIME() return the current date and time in the server’s local time zone. When you need global consistency, SQL Server also provides GETUTCDATE() and SYSUTCDATETIME(), which return the same values adjusted to Coordinated Universal Time (UTC).

Quick comparison: GETDATE() returns the local system time, while GETUTCDATE() returns the equivalent in UTC.

GETUTCDATE()

GETUTCDATE() returns the current UTC date and time in the format yyyy-mm-dd hh:mm:ss.mmm. The value is based on the operating system of the computer where SQL Server is running, converted to UTC.

Syntax

SELECT 
    GETUTCDATE();
GETUTCDATE() returning UTC datetime in dbForge Studio.

SYSUTCDATETIME()

SYSUTCDATETIME() returns a datetime2(7) value in UTC with precision up to 100 nanoseconds. Like GETUTCDATE(), the result is derived from the host system but provides finer temporal detail.

Syntax

SELECT 
    SYSUTCDATETIME();
SYSUTCDATETIME() returning high-precision UTC datetime in dbForge Studio for SQL Server.

Both functions are useful for applications that require global timekeeping, such as multi-region databases, cross-border reporting, or audit logs that must align across different time zones.

Converting between time zones

To convert between time zones in SQL Server, use the AT TIME ZONE clause. This feature, introduced in SQL Server 2016, lets you take a datetime value and return it in the time zone you specify. By default, SQL Server works in UTC, but many applications require local or regional time adjustments.

You’ll typically need this in scenarios such as:

  • SaaS applications serving users across multiple countries.
  • Multi-region servers where logs must display in each user’s local time.
  • Global reporting where timestamps need to align across time zones.

Syntax

SELECT
  inputdate AT TIME ZONE destination_time_zone;

To view the list of supported time zones in SQL Server, run the following code:

SELECT
  *
FROM sys.time_zone_info
Listing supported time zones in SQL Server using sys.time_zone_info.

Example: Convert from UTC to Pacific Standard Time

SELECT  
    CAST('2026-01-16T10:00:00' AS DATETIME2) 
    AT TIME ZONE 'UTC' 
    AT TIME ZONE 'Pacific Standard Time' AS PST;
Converting from UTC to Pacific Standard Time using AT TIME ZONE.

The accepted input types are SMALLDATETIME, DATETIME, and DATETIME2. The result is returned as a DATETIMEOFFSET value.

By default, the regional database settings are set to UTC. However, there may be cases where you need to query data directly and view the local date and time or calculate the date and time for another region.

Formatting the date and time

To format date and time output in SQL Server, use CONVERT(), CAST(), or FORMAT(). These functions allow you to transform a datetime value into a specific display format or string type.

Formatting is critical in scenarios such as:

  • Reports, where dates need to be human-readable (e.g., 17-Jan-2026).
  • Logs, where consistency in timestamp format ensures easier debugging.
  • Cross-regional data exchanges, where local conventions differ (e.g., MM/dd/yyyy vs. dd/MM/yyyy).

Each function offers a different level of control:

  • CAST() performs simple type conversion.
  • CONVERT() provides style codes for predefined formats.
  • FORMAT() gives the most flexibility with custom patterns and localization.

Below, we’ll explore each function with examples.

Using the CAST() and CONVERT() functions

Assume we need to convert the datetime value into a VARCHAR with the help of the CAST() function. The query is as follows:

SELECT
  CAST('2026-01-17 18:45:00' AS VARCHAR(20)) AS 'ConvertedValue';

The output is in the VARCHAR format:

Datetime value converted to VARCHAR.

The CONVERT() function allows you to convert a DATETIME value into a string (VARCHAR) with a specific format. The format is controlled by a style code, a numeric value that defines how the date will appear.

The syntax is as follows:

SELECT
  CONVERT(VARCHAR, datetime_value, style)

The most common style codes are listed below:

Style Output format Example output
101 U.S. Format (mm/dd/yyyy) 12/17/2025
103 British/French Format (dd/mm/yyyy) 17/12/2025
104 German Format (dd.mm.yyyy) 17.12.2025
108 Time only (hh:mm:ss) 14:30:00
110 U.S. Format with hyphens (mm-dd-yyyy) 12-17-2025
112 ISO Format (yyyymmdd) 20251217
121 ISO 8601 Format with milliseconds 2025-12-17 14:30:00.000

If no style is specified, the default format is used, which may vary based on server settings.

We can perform several format conversions with one query:

DECLARE @DateTimeValue DATETIME = '2026-01-17 19:30:00';

SELECT
  CONVERT(VARCHAR, @DateTimeValue, 121) AS ISOFormat
 ,  -- ISO 8601 format
  CONVERT(VARCHAR, @DateTimeValue, 103) AS BritishFormat
 , -- dd/mm/yyyy
  CONVERT(VARCHAR, @DateTimeValue, 101) AS USFormat;
dbForge Studio for SQL Server is showing SQL CONVERT() output in ISO 8601, British (dd/MM/yyyy), and US (MM/dd/yyyy) date formats.

Using the correct style code allows you to adapt the output to regional or application requirements easily.

Using the FORMAT() function

To display dates in custom formats such as dd-MMM-yyyy, use FORMAT(). This function is the most flexible way to transform a datetime value into a string, supporting custom pattern strings and even regional or language-specific formats.

Syntax

FORMAT(datetime_value, 'format_string' [, 'culture']);

Parameters:

  • datetime_value: The date or datetime to format.
  • format_string: A .NET-style format pattern (e.g., yyyy-MM-dd HH:mm:ss).
  • culture (optional): The locale, such as en-US, fr-FR, or de-DE, to localize month and day names.

Common and uncommon pattern examples

1. Abbreviated month name:

SELECT 
    FORMAT(GETDATE(), 'dd-MMM-yyyy') AS ReportDate;
Using FORMAT() to display date as dd-MMM-yyyy.

2. 24-hour timestamp:

SELECT 
    FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm:ss') AS LogStamp;
Using FORMAT() to display date and time in yyyy-MM-dd HH:mm:ss format.

3. Full month name:

SELECT 
    FORMAT(GETDATE(), 'MMMM dd, yyyy') AS FullDate;

4. Localized month name (French):

SELECT 
    FORMAT(GETDATE(), 'dd MMMM yyyy', 'fr-FR') AS FrenchDate;

Unlike CONVERT(), which uses predefined style codes, FORMAT() gives you full control with custom patterns and localization.

Date and time arithmetic

Handling time intervals, such as adding or subtracting durations and calculating the difference between dates, is a common task in database management. SQL Server provides specialized functions to manage these operations efficiently.

Add and subtract time intervals with DATEADD()

To add or subtract days, months, or years from a date in SQL Server, use DATEADD(). This function shifts a date by the interval you specify, making it useful for scheduling and time-based calculations.

How to use DATEADD():

  1. Choose the interval (e.g., DAY, MONTH, YEAR).
  2. Specify the value to add (positive number) or subtract (negative number).
  3. Provide the date expression.

Syntax:

DATEADD(interval, number, date)

Parameters:

  • interval:The part of the date to modify. Common options: year, quarter, month, day, week, hour, minute, second.
  • number: The value to add (positive) or subtract (negative).
  • date: The datetime expression to update. Accepted types: date, datetime, datetime2, smalldatetime, datetimeoffset, time.
Note

The DATEADD() function accepts various date data types, such as DATETIME and DATE. If the input date is not compatible with the specified date part, SQL Server performs an implicit conversion. This may lead to unexpected results, so it is best to ensure the types align with the calculation.

Examples of using DATEADD()

Here are a few examples of applying DATEADD() in real-world:

1. Add 7 days to the current date (e.g., calculate a due date):

SELECT 
    DATEADD(DAY, 7, GETDATE()) AS NextWeek;
DATEADD() query in dbForge Studio adding 7 days to the current date.

2. Subtract 10 days from the current date (e.g., find recent activity):

SELECT 
    DATEADD(DAY, -10, GETDATE()) AS TenDaysAgo;
DATEADD() query in dbForge Studio subtracting 10 days from the current date.

3. Add 1 month to today’s date (e.g., calculate the next payment date):

SELECT 
    DATEADD(MONTH, 1, GETDATE()) AS NextPayment;

Real-life use cases include:

  • Calculating the next payment date in billing systems.
  • Generating reminders or deadlines.
  • Pulling data for a lookback period (e.g., past 30 days of orders).
  • Scheduling tasks that run at fixed intervals.

Calculate differences between dates with DATEDIFF()

The DATEDIFF() function calculates the difference between two dates or timestamps in a specified unit (e.g., days, months, years).

Syntax

SELECT 
    DATEDIFF(datepart, startdate, enddate);

Parameters:

  • datepart: The time unit to measure the difference. Common values: year, quarter, month, day, hour, minute, second.
  • startdate: The starting date or timestamp in the calculation.
  • enddate: The ending date or timestamp in the calculation.

Example: Calculating the difference in months between two dates

SELECT 
  DATEDIFF(MONTH, '2026-01-17', '2023-06-01') AS 'Difference';
DATEDIFF() query in dbForge Studio for SQL Server is showing month difference result.

Try it yourself with dbForge Studio

Want to try all these date functions in one interface? Use dbForge Studio for SQL Server. It’s an integrated SQL IDE that lets you:

  • Run queries interactively and see results instantly.
  • Automate routine tasks like formatting and conversions.
  • Explore system tables, functions, and time zone info in a visual way.

dbForge Studio for SQL Server provides a more powerful alternative to SSMS, combining query execution with productivity features like code completion, debugging, and schema management.

For details about how it compares to SSMS, check out the Features Comparison of SSMS vs. dbForge Studio for SQL Server on the Devart YouTube channel.

Devart provides a 30-day fully functional free trial, so you can test the Studio's capabilities under a full workload. Download and install the software to see how it copes with your daily tasks.

Further learning

The following guides can be helpful when working with SQL queries: