Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Calculate Age

Posted on September 18, 2013October 26, 2015 By David Kittell
public static Int32 GetAge(this DateTime dateOfBirth)
{
    var today = DateTime.Today;

    var a = (today.Year * 100 + today.Month) * 100 + today.Day;
    var b = (dateOfBirth.Year * 100 + dateOfBirth.Month) * 100 + dateOfBirth.Day;

    return (a - b) / 10000;
}
var now = float.Parse(DateTime.Now.ToString("yyyy.MMdd"));
var dob = float.Parse(dateOfBirth.ToString("yyyy.MMdd"));
var age = (int)(now - dob);

Source: http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c

Originally Posted on September 18, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp

Post navigation

Previous post
Next post

Related Posts

Windows OS Version

Posted on December 14, 2013October 26, 2015

Public Function GetOSVersion() As String Dim sOSType As String = "" Select Case Environment.OSVersion.Platform Case PlatformID.Win32S sOSType = "Win 3.1" Case PlatformID.Win32Windows Select Case Environment.OSVersion.Version.Minor Case 0 sOSType = "Win95" Case 10 sOSType = "Win98" Case 90 sOSType = "WinME" Case Else sOSType = "Unknown" End Select Case PlatformID.Win32NT Select…

Read More

WordPress Change URL – MySQL – Update String Within Column

Posted on October 17, 2014January 15, 2021

Recently I changed a domain alias for a WordPress site and needed to change the domain in all the pages/posts and this little script came in handy. Typical disclaimer stands, do a full backup before running this and verify you have everything setup correctly. UPDATE wp_options SET option_value = REPLACE(option_value,…

Read More

Azure CLI – List All VMs with Details

Posted on December 24, 2017

az vm list –show-details –query ‘[].{VMName:name, OSType:storageProfile.osDisk.osType,VMSize:hardwareProfile.vmSize, Location: location,ResourceGroup:resourceGroup,PowerState:powerState, privateIPs: privateIps}’ -o table All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes