This month's discount Comprehensive Database Performance Health Check · Testimonials
SQLAuthority with Pinal Dave
Home
  • Consulting
    • Health Check
  • Free Videos
  • All Articles
    • AI
    • SQL Performance
    • SQL Tips and Tricks
    • Interview Questions and Answers
    • SQL Puzzle
    • SQL Video
    • SQLAuthority News
    • Personal
  • Books
  • Consulting
Gouache painting of a cream wrapped gift with a red ribbon on a patio table beside a pitcher of lemonade and a paper party hat

How to Calculate Age Correctly in SQL Server

July 30, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts

Calculate Age in SQL Server by counting completed birthdays, not calendar years. This post compares DATEDIFF, a DATEADD correction and a compact integer version on a bike club table, handles February 29 birthdays and ends with a reusable function for age on any date.

Read More
SQL SERVER - 2008 - SQL Server Start Time

SQL SERVER – 2008 – SQL Server Start Time

June 17, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Scripts

SQL Server 2008 records when it started in sys.dm_os_sys_info. One SELECT of sqlserver_start_time gives you the SQL Server start time. It does not work on 2005.

Read More
Six unmarked stone tiles in a row in front of a plain wooden strip.

DATETRUNC: Use ISO Week Boundaries With Explicit Date Types

June 12, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL Server

DATETRUNC can give an ISO week its Monday boundary without changing session settings. I also keep the input date type explicit. A boundary calculation should reveal both its calendar rule and its return type.

Read More
SQL SERVER - SQL SERVER - UDF - Get the Day of the Week Function - Part 4

SQL SERVER – SQL SERVER – UDF – Get the Day of the Week Function Part 4

June 1, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts

In Day of the Week Function Part 4, I answer why I write a UDF when DATENAME exists (I just like it) and show the one line DATENAME version.

Read More
SQL SERVER - SQL SERVER - UDF - Get the Day of the Week Function - Part 3

SQL SERVER – SQL SERVER – UDF – Get the Day of the Week Function – Part 3

May 27, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts

Nanda Kumar improved the UDF to get the day of the week: it now uses the date you pass in instead of GETDATE() and handles Saturday correctly.

Read More
SQL SERVER - SQL SERVER - UDF - Get the Day of the Week Function - Part 2

SQL SERVER – SQL SERVER – UDF – Get the Day of the Week Function – Part 2

May 23, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts

Mihir Popat improved my Day of the Week Function with @@DATEFIRST, so Sunday does not have to be the first day of the week. Here is his UDF.

Read More
Gouache painting: seen from above, three furrows lie side by side: one long, one shorter, one long

EOMONTH: Month Ends Are Different From DATEADD Month Clipping

April 21, 2008
Pinal Dave
SQL Tips and Tricks
SQL DateTime, SQL Function, SQL Scripts, SQL Server

EOMONTH gives me a month-end date when that is the actual reporting requirement. DATEADD moves a date by a month. These operations can agree for one step and disagree on the next.

Read More
Previous 1 … 22 23 24 25 26 27 28 29 Next
  • Books
  • Testimonials
  • Privacy Policy

© 2006 – 2026 All rights reserved. pinal @ SQLAuthority.com