About 3,950,000 results
Open links in new tab
  1. sql - How to calculate age (in years) based on Date of Birth and ...

    Oct 15, 2009 · Here is how i calculate age given a birth date and current date. select case when cast(getdate() as date) = cast(dateadd(year, (datediff(year, '1996-09-09', getdate())), '1996-09-09') as date) then dateDiff(yyyy,'1996-09-09',dateadd(year, 0, getdate())) else dateDiff(yyyy,'1996-09-09',dateadd(year, -1, getdate())) end as MemberAge go

  2. How to calculate age in T-SQL with years, months, and days

    Jan 5, 2014 · Simple way to get age as text is as below: cast((DATEDIFF(m, date_of_birth, GETDATE())%12) as varchar) + ' M' as Age. Results Format will be: Implemented by arithmetic with ISO formatted date. + (sign(day(@dob) - day(@now))+1)/2 * (@days_in_birth_month - day(@dob) + day(@now))

  3. How to calculate age in SQL: Use THIS simple script!

    Apr 1, 2024 · We can use the DATEDIFF and DATEADD system functions (and a bit of cleverness) to calculate the age of a person based on their date of birth!

  4. Calculating Age with a User-Defined Function - wiseowl.co.uk

    A neat solution for avoiding finger-ache is to create a user-defined function that you can then call upon each time you need to calculate age. This article isn't meant to be a comprehensive tutorial on creating user-defined functions in SQL Server; for that you'll want to look up the relevant article on our SQL Tutorial page.

  5. How to Calculate Age in SQL - wiseowl.co.uk

    Using DATEDIFF to Calculate Age. Apparently, the quickest and easiest way to calculate the age of someone or something in years is to simply use the DATEDIFF function.

  6. How to Calculate Age from Date of Birth in SQL Server: A Step …

    Method 1: Using DATEDIFF. This method is very simple to calculate age from date of birth in SQL by using DATEDIFF function. This function calculates the difference between two dates in a specific unit, such as year, month, and minutes. Example: SELECT DATEDIFF(YEAR, DateOfBirth, GETDATE()) AS Age FROM YourTable;

  7. 9+ SQL Age Calculation Queries: Easy Guide

    Jan 22, 2025 · Determining a person's age from their date of birth within a database is a common requirement in many applications. Structured Query Language (SQL) provides several functions to perform this calculation, typically involving the current date and the stored birth date. For example, some database systems offer dedicated age calculation functions, while others might require using date difference ...

  8. SQL Age Calculation: 7+ Effective Methods

    Jan 19, 2025 · Determining a person's age from a date of birth stored in a database is a common requirement in many applications. SQL provides several functions to perform this calculation, typically by subtracting the birth date from the current date. For instance, in PostgreSQL, the `age()` function directly calculates the difference, returning an interval data type representing the age. Other database ...

  9. MySQL :: MySQL 9.3 Reference Manual :: 5.3.4.5 Date Calculations

    To determine how many years old each of your pets is, use the TIMESTAMPDIFF() function. Its arguments are the unit in which you want the result expressed, and the two dates for which to take the difference. The following query shows, for each pet, the birth date, the current date, and the age in years.

  10. Microsoft SQL Server Tutorial => Create function to calculate a...

    Jan 1, 2000 · This function will take 2 datetime parameters, the DOB, and a date to check the age at. CREATE FUNCTION [dbo].[Calc_Age] ( @DOB datetime , @calcDate datetime ) RETURNS int AS BEGIN declare @age int IF (@calcDate < @DOB ) RETURN -1 -- If a DOB is supplied after the comparison date, then return -1 SELECT @age = YEAR(@calcDate) - …

  11. Some results have been removed
Refresh