{"id":1160,"date":"2025-05-01T18:57:14","date_gmt":"2025-05-01T18:57:14","guid":{"rendered":"https:\/\/kourentzes.com\/konstantinos\/?p=1160"},"modified":"2025-05-01T18:57:15","modified_gmt":"2025-05-01T18:57:15","slug":"t-sql-date-functions-sql-server","status":"publish","type":"post","link":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/","title":{"rendered":"The Most Common Date Functions in T-SQL"},"content":{"rendered":"\n<p>Working with dates and times is a fundamental aspect of database development and reporting. T-SQL (Transact-SQL), Microsoft&#8217;s extension of SQL, offers a robust set of functions to handle date and time values efficiently. This article presents the most commonly used <strong>date functions in T-SQL<\/strong>, organized by category and use case, with syntax, examples, and notes on performance.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>GETDATE() and SYSDATETIME()<\/strong><\/h2>\n\n\n\n<p>Returns the current system date and time.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Function<\/th><th>Returns<\/th><th>Precision<\/th><\/tr><\/thead><tbody><tr><td><code>GETDATE()<\/code><\/td><td><code>datetime<\/code><\/td><td>3.33 ms<\/td><\/tr><tr><td><code>SYSDATETIME()<\/code><\/td><td><code>datetime2<\/code><\/td><td>100 ns<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT GETDATE();        -- e.g., 2025-05-01 14:32:45.340\nSELECT SYSDATETIME();    -- e.g., 2025-05-01 14:32:45.3401234\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">();        <\/span><span style=\"color: #545454; font-style: italic\">-- e.g., 2025-05-01 14:32:45.340<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">SYSDATETIME<\/span><span style=\"color: #EEFFFF\">();    <\/span><span style=\"color: #545454; font-style: italic\">-- e.g., 2025-05-01 14:32:45.3401234<\/span><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>Use <code>SYSDATETIME()<\/code> when you need higher precision.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. <strong>DATEPART(), DATENAME(), YEAR(), MONTH(), DAY()<\/strong><\/h2>\n\n\n\n<p>These functions extract components of a date.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Function<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>DATEPART(part, date)<\/code><\/td><td>Returns an integer of the date part.<\/td><\/tr><tr><td><code>DATENAME(part, date)<\/code><\/td><td>Returns the name (e.g., Monday).<\/td><\/tr><tr><td><code>YEAR(date)<\/code><\/td><td>Extracts the year.<\/td><\/tr><tr><td><code>MONTH(date)<\/code><\/td><td>Extracts the month (1-12).<\/td><\/tr><tr><td><code>DAY(date)<\/code><\/td><td>Extracts the day of the month.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT DATEPART(weekday, GETDATE()); -- e.g., 5 (Friday)\nSELECT DATENAME(weekday, GETDATE()); -- e.g., 'Friday'\nSELECT YEAR(GETDATE());              -- e.g., 2025\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATEPART<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">weekday<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">()); <\/span><span style=\"color: #545454; font-style: italic\">-- e.g., 5 (Friday)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATENAME<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">weekday<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">()); <\/span><span style=\"color: #545454; font-style: italic\">-- e.g., &#39;Friday&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">YEAR<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">());              <\/span><span style=\"color: #545454; font-style: italic\">-- e.g., 2025<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. <strong>DATEADD()<\/strong><\/h2>\n\n\n\n<p>Adds (or subtracts) a time interval to a date.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"-- Add 10 days\nSELECT DATEADD(day, 10, '2025-05-01');  -- 2025-05-11\n\n-- Subtract 1 month\nSELECT DATEADD(month, -1, '2025-05-01'); -- 2025-04-01\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Add 10 days<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATEADD<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">day<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #F78C6C\">10<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);  <\/span><span style=\"color: #545454; font-style: italic\">-- 2025-05-11<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Subtract 1 month<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATEADD<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">month<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">-<\/span><span style=\"color: #F78C6C\">1<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">); <\/span><span style=\"color: #545454; font-style: italic\">-- 2025-04-01<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>This is critical for rolling time windows, future projections, etc.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. <strong>DATEDIFF()<\/strong><\/h2>\n\n\n\n<p>Calculates the difference between two dates, in terms of a specified date part.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"-- Days between dates\nSELECT DATEDIFF(day, '2025-01-01', '2025-05-01'); -- 120\n\n-- Months between dates\nSELECT DATEDIFF(month, '2024-05-01', '2025-05-01'); -- 12\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Days between dates<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATEDIFF<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">day<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-01-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">); <\/span><span style=\"color: #545454; font-style: italic\">-- 120<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Months between dates<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">DATEDIFF<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #F78C6C\">month<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2024-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">); <\/span><span style=\"color: #545454; font-style: italic\">-- 12<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>Returns <em>whole<\/em> number differences. Always be mindful of truncation behavior.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>EOMONTH()<\/strong><\/h2>\n\n\n\n<p>Returns the <strong>last day<\/strong> of the month that contains the specified date.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT EOMONTH('2025-05-01');        -- 2025-05-31\nSELECT EOMONTH('2025-05-01', 1);     -- 2025-06-30\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">EOMONTH<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);        <\/span><span style=\"color: #545454; font-style: italic\">-- 2025-05-31<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">EOMONTH<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #F78C6C\">1<\/span><span style=\"color: #EEFFFF\">);     <\/span><span style=\"color: #545454; font-style: italic\">-- 2025-06-30<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>Perfect for financial or monthly reporting.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6. <strong>SWITCHOFFSET() and TODATETIMEOFFSET()<\/strong><\/h2>\n\n\n\n<p>Used when working with <strong>time zones<\/strong> and <code>datetimeoffset<\/code> data types.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"-- Adjust to UTC+2\nSELECT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+02:00');\n\n-- Set an offset explicitly\nSELECT TODATETIMEOFFSET(SYSDATETIME(), '+03:00');\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Adjust to UTC+2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">SWITCHOFFSET<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #82AAFF\">SYSDATETIMEOFFSET<\/span><span style=\"color: #EEFFFF\">(), <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">+02:00<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Set an offset explicitly<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">TODATETIMEOFFSET<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #82AAFF\">SYSDATETIME<\/span><span style=\"color: #EEFFFF\">(), <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">+03:00<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>These functions are crucial for global applications with multiple time zones.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7. <strong>CONVERT() and CAST()<\/strong> (For Formatting and Type Conversion)<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"-- Convert to date only\nSELECT CONVERT(date, GETDATE());      -- 2025-05-01\n\n-- Convert to string\nSELECT CONVERT(varchar, GETDATE(), 120); -- '2025-05-01 14:35:00'\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Convert to date only<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">CONVERT<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #C792EA\">date<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">());      <\/span><span style=\"color: #545454; font-style: italic\">-- 2025-05-01<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #545454; font-style: italic\">-- Convert to string<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">CONVERT<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #C792EA\">varchar<\/span><span style=\"color: #EEFFFF\">, <\/span><span style=\"color: #82AAFF\">GETDATE<\/span><span style=\"color: #EEFFFF\">(), <\/span><span style=\"color: #F78C6C\">120<\/span><span style=\"color: #EEFFFF\">); <\/span><span style=\"color: #545454; font-style: italic\">-- &#39;2025-05-01 14:35:00&#39;<\/span><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Style Code<\/th><th>Format Example<\/th><\/tr><\/thead><tbody><tr><td>103<\/td><td>dd\/mm\/yyyy<\/td><\/tr><tr><td>112<\/td><td>yyyymmdd (ISO)<\/td><\/tr><tr><td>120<\/td><td>yyyy-mm-dd hh:mi:ss (ISO)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>&#x1f4cc; Use <code>CAST()<\/code> for ANSI SQL compatibility, and <code>CONVERT()<\/code> when style formatting is needed.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus: <strong>ISDATE()<\/strong><\/h2>\n\n\n\n<p>Checks if a string can be converted to a valid date.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#212121\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"SELECT ISDATE('2025-05-01');     -- 1 (true)\nSELECT ISDATE('not-a-date');     -- 0 (false)\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-darker\" style=\"background-color: #212121\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">ISDATE<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">2025-05-01<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);     <\/span><span style=\"color: #545454; font-style: italic\">-- 1 (true)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F78C6C\">SELECT<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #82AAFF\">ISDATE<\/span><span style=\"color: #EEFFFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">not-a-date<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #EEFFFF\">);     <\/span><span style=\"color: #545454; font-style: italic\">-- 0 (false)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><span style=\"display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#212121;color:#d5ffff;font-size:12px;line-height:1;position:relative\">SQL<\/span><\/div>\n\n\n\n<p>Great for <strong>data validation<\/strong> in dynamic T-SQL scripts.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Function<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>GETDATE()<\/code><\/td><td>Current system datetime<\/td><\/tr><tr><td><code>SYSDATETIME()<\/code><\/td><td>High-precision current datetime<\/td><\/tr><tr><td><code>DATEPART()<\/code><\/td><td>Extract part of a date as int<\/td><\/tr><tr><td><code>DATENAME()<\/code><\/td><td>Extract part of a date as string<\/td><\/tr><tr><td><code>DATEADD()<\/code><\/td><td>Add\/subtract date parts<\/td><\/tr><tr><td><code>DATEDIFF()<\/code><\/td><td>Calculate difference between dates<\/td><\/tr><tr><td><code>EOMONTH()<\/code><\/td><td>Get last day of the month<\/td><\/tr><tr><td><code>CONVERT()<\/code><\/td><td>Format and convert date types<\/td><\/tr><tr><td><code>ISDATE()<\/code><\/td><td>Check if value is a valid date<\/td><\/tr><tr><td><code>SWITCHOFFSET()<\/code><\/td><td>Adjust timezone for datetimeoffset<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<p>Mastering these T-SQL date functions can save you countless hours when dealing with reporting, data transformations, and analytics. Whether you&#8217;re building a <strong>monthly dashboard<\/strong>, cleaning up <strong>dirty data<\/strong>, or optimizing for <strong>time-based queries<\/strong>, these tools form the backbone of time manipulation in SQL Server.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.<\/p>\n","protected":false},"author":1,"featured_media":1161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10,863],"tags":[867,866,868,870,865,875,872,869,143,873,871,42,876,874,864],"class_list":["post-1160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-snipperts","category-t-sql","tag-date-functions","tag-sql-convert-datetime","tag-sql-dateadd","tag-sql-datediff","tag-sql-datetime","tag-sql-datetime-examples","tag-sql-eomonth","tag-sql-getdate","tag-sql-server","tag-sql-server-functions","tag-sql-tips","tag-t-sql","tag-transact-sql","tag-tsql-cheat-sheet","tag-tsql-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com<\/title>\n<meta name=\"description\" content=\"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com\" \/>\n<meta property=\"og:description\" content=\"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"konstantinos.kourentzes.com\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-01T18:57:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-01T18:57:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Konstantinos Kourentzes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@kkourentzes\" \/>\n<meta name=\"twitter:site\" content=\"@kkourentzes\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Konstantinos Kourentzes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/\"},\"author\":{\"name\":\"Konstantinos Kourentzes\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#\\\/schema\\\/person\\\/2693fb0ad7f7638a020431ffe372c822\"},\"headline\":\"The Most Common Date Functions in T-SQL\",\"datePublished\":\"2025-05-01T18:57:14+00:00\",\"dateModified\":\"2025-05-01T18:57:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/\"},\"wordCount\":378,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#\\\/schema\\\/person\\\/2693fb0ad7f7638a020431ffe372c822\"},\"image\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png\",\"keywords\":[\"date functions\",\"sql convert datetime\",\"sql dateadd\",\"sql datediff\",\"sql datetime\",\"sql datetime examples\",\"sql eomonth\",\"sql getdate\",\"SQL Server\",\"sql server functions\",\"sql tips\",\"t-sql\",\"transact-sql\",\"tsql cheat sheet\",\"tsql tutorial\"],\"articleSection\":[\"Code Snippets\",\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/\",\"url\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/\",\"name\":\"The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png\",\"datePublished\":\"2025-05-01T18:57:14+00:00\",\"dateModified\":\"2025-05-01T18:57:15+00:00\",\"description\":\"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png\",\"contentUrl\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png\",\"width\":1024,\"height\":1024,\"caption\":\"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/2025\\\/05\\\/01\\\/t-sql-date-functions-sql-server\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Most Common Date Functions in T-SQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#website\",\"url\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/\",\"name\":\"kourentzes.com\\\/konstantinos\",\"description\":\"Konstantinos Kourentzes\",\"publisher\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#\\\/schema\\\/person\\\/2693fb0ad7f7638a020431ffe372c822\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/#\\\/schema\\\/person\\\/2693fb0ad7f7638a020431ffe372c822\",\"name\":\"Konstantinos Kourentzes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/kko.png\",\"url\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/kko.png\",\"contentUrl\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/kko.png\",\"width\":2835,\"height\":2268,\"caption\":\"Konstantinos Kourentzes\"},\"logo\":{\"@id\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/kko.png\"},\"description\":\"Konstantinos Kourentzes is a distinguished technologist and Enterprise Resource Planning (ERP) consultant renowned for his expertise in delivering cutting-edge technology solutions. Based in Marousi, Greece, he has a knack for seamlessly integrating data-driven systems, empowering businesses to streamline their operations and achieve peak efficiency. A fervent proponent of innovation, Konstantinos is committed to instigating revolutionary shifts within organizations. His approach revolves around delivering custom-tailored ERP solutions that seamlessly align with each business's distinctive requirements. This catalyzes enduring collaborations rooted in unwavering trust and tangible outcomes. With a background rooted in technology and a passion for optimizing business processes, Konstantinos is your go-to partner for harnessing the power of ERP systems to unlock operational excellence. Connect with Konstantinos on LinkedIn to explore how his technological insights can drive your business to new heights.\",\"sameAs\":[\"https:\\\/\\\/kourentzes.com\\\/konstantinos\",\"https:\\\/\\\/x.com\\\/kkourentzes\"],\"url\":\"https:\\\/\\\/kourentzes.com\\\/konstantinos\\\/index.php\\\/author\\\/administrator\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com","description":"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com","og_description":"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.","og_url":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/","og_site_name":"konstantinos.kourentzes.com","article_published_time":"2025-05-01T18:57:14+00:00","article_modified_time":"2025-05-01T18:57:15+00:00","og_image":[{"width":1024,"height":1024,"url":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png","type":"image\/png"}],"author":"Konstantinos Kourentzes","twitter_card":"summary_large_image","twitter_creator":"@kkourentzes","twitter_site":"@kkourentzes","twitter_misc":{"Written by":"Konstantinos Kourentzes","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#article","isPartOf":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/"},"author":{"name":"Konstantinos Kourentzes","@id":"https:\/\/kourentzes.com\/konstantinos\/#\/schema\/person\/2693fb0ad7f7638a020431ffe372c822"},"headline":"The Most Common Date Functions in T-SQL","datePublished":"2025-05-01T18:57:14+00:00","dateModified":"2025-05-01T18:57:15+00:00","mainEntityOfPage":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/"},"wordCount":378,"commentCount":0,"publisher":{"@id":"https:\/\/kourentzes.com\/konstantinos\/#\/schema\/person\/2693fb0ad7f7638a020431ffe372c822"},"image":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png","keywords":["date functions","sql convert datetime","sql dateadd","sql datediff","sql datetime","sql datetime examples","sql eomonth","sql getdate","SQL Server","sql server functions","sql tips","t-sql","transact-sql","tsql cheat sheet","tsql tutorial"],"articleSection":["Code Snippets","T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/","url":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/","name":"The Most Common Date Functions in T-SQL - konstantinos.kourentzes.com","isPartOf":{"@id":"https:\/\/kourentzes.com\/konstantinos\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#primaryimage"},"image":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png","datePublished":"2025-05-01T18:57:14+00:00","dateModified":"2025-05-01T18:57:15+00:00","description":"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips.","breadcrumb":{"@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#primaryimage","url":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png","contentUrl":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2025\/05\/emperor_kk_Master_the_most_useful_T-SQL_date_functions_in_SQL_26a41cf3-33ec-4b9e-b527-5bfad4b50069_31.png","width":1024,"height":1024,"caption":"Master the most useful T-SQL date functions in SQL Server. Learn how to use GETDATE, DATEADD, DATEDIFF, EOMONTH, and more with practical examples and tips."},{"@type":"BreadcrumbList","@id":"https:\/\/kourentzes.com\/konstantinos\/index.php\/2025\/05\/01\/t-sql-date-functions-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kourentzes.com\/konstantinos\/"},{"@type":"ListItem","position":2,"name":"The Most Common Date Functions in T-SQL"}]},{"@type":"WebSite","@id":"https:\/\/kourentzes.com\/konstantinos\/#website","url":"https:\/\/kourentzes.com\/konstantinos\/","name":"kourentzes.com\/konstantinos","description":"Konstantinos Kourentzes","publisher":{"@id":"https:\/\/kourentzes.com\/konstantinos\/#\/schema\/person\/2693fb0ad7f7638a020431ffe372c822"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kourentzes.com\/konstantinos\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/kourentzes.com\/konstantinos\/#\/schema\/person\/2693fb0ad7f7638a020431ffe372c822","name":"Konstantinos Kourentzes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2022\/02\/kko.png","url":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2022\/02\/kko.png","contentUrl":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2022\/02\/kko.png","width":2835,"height":2268,"caption":"Konstantinos Kourentzes"},"logo":{"@id":"https:\/\/kourentzes.com\/konstantinos\/wp-content\/uploads\/2022\/02\/kko.png"},"description":"Konstantinos Kourentzes is a distinguished technologist and Enterprise Resource Planning (ERP) consultant renowned for his expertise in delivering cutting-edge technology solutions. Based in Marousi, Greece, he has a knack for seamlessly integrating data-driven systems, empowering businesses to streamline their operations and achieve peak efficiency. A fervent proponent of innovation, Konstantinos is committed to instigating revolutionary shifts within organizations. His approach revolves around delivering custom-tailored ERP solutions that seamlessly align with each business's distinctive requirements. This catalyzes enduring collaborations rooted in unwavering trust and tangible outcomes. With a background rooted in technology and a passion for optimizing business processes, Konstantinos is your go-to partner for harnessing the power of ERP systems to unlock operational excellence. Connect with Konstantinos on LinkedIn to explore how his technological insights can drive your business to new heights.","sameAs":["https:\/\/kourentzes.com\/konstantinos","https:\/\/x.com\/kkourentzes"],"url":"https:\/\/kourentzes.com\/konstantinos\/index.php\/author\/administrator\/"}]}},"_links":{"self":[{"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":1,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"predecessor-version":[{"id":1162,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/posts\/1160\/revisions\/1162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/media\/1161"}],"wp:attachment":[{"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kourentzes.com\/konstantinos\/index.php\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}