Here you can find the source of calculateAge(Date DOB)
Parameter | Description |
---|---|
date | SQL formatted date string. |
public static synchronized int calculateAge(Date DOB)
//package com.java2s; /*// w w w. j a v a 2 s .c o m * $Id$ * * Authors: * Jeff Buchbinder <jeff@freemedsoftware.org> * * FreeMED Electronic Medical Record and Practice Management System * Copyright (C) 1999-2012 FreeMED Software Foundation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /** * Calculates age w.r.t provided DOB * * @param date * SQL formatted date string. * @return age */ public static synchronized int calculateAge(Date DOB) { int age = -1; Calendar calDOB = new GregorianCalendar(); calDOB.setTime(DOB); Calendar calNow = new GregorianCalendar(); calNow.setTime(new Date()); age = calNow.get(Calendar.YEAR) - calDOB.get(Calendar.YEAR); return age; } }