Process Mapping Logo

Process Mapping - Forums

Sharing 19 years of knowledge and experience

 
Metastorm BPM forums
Sign up Latest Topics
 
 
 


Reply
  Author   Comment   Page 2 of 2      Prev   1   2
mohnshine

Avatar / Picture

Senior Veteran
Registered:
Posts: 270
Reply with quote  #16 
These both give the same results
    datediff(dd,BirthDate, getdate())
    datediff(dy,BirthDate, getdate())

If you use 6/26/1955 for the birthdate, you will get 20000 days on today (3/29/2009).  Dividing by 365.25 will translate to 54 years old, and will be 55 on 6/26/2020.

BTW 6/26/1955 is not my birthday, just liked the nice round number it gave back.

__________________
Your best practice does not conform with my best practice.
0
Jerome

Avatar / Picture

Guru
Registered:
Posts: 5,507
Reply with quote  #17 
Hmmmm.

To be fully accurate I guess it should count the months and the days of the month. I'll check to see if it needs to be that accurate. At least this is more accurate than the previous, anyway.


__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.
0
Jerome

Avatar / Picture

Guru
Registered:
Posts: 5,507
Reply with quote  #18 
Well, here's my (hopefully) final take on it:

Quote:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AgeAt]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[AgeAt]
GO

CREATE FUNCTION dbo.AgeAt
(
    @BirthDate    datetime,
    @AtDate        datetime
)
RETURNS int
AS
BEGIN
    DECLARE @Age int;

    SET @Age =
    (
        SELECT datediff(year,@BirthDate,@AtDate)
            - case when
            (
                datepart(mm,@BirthDate) > datepart(mm,@AtDate) OR
                (
                    datepart(mm,@BirthDate) = datepart(mm,@AtDate)
                    AND datepart(dd,@BirthDate) > datepart(dd,@AtDate)
                )
            ) then 1 else 0 end
    )

    RETURN(@Age)
END



__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.
0
Nappy

Avatar / Picture

Guru
Registered:
Posts: 1,087
Reply with quote  #19 
Quote:

function yearsOld(){
   birthday = new Date("12/1/1967");
   today = new Date();
   years = today.getFullYear() - birthday.getFullYear();
   birthday.setYear( today.getFullYear() );
   // If your birthday hasn't occurred yet this year, subtract 1.
   if(today < birthday){
      years-- ;   }
   alert("You are " + years + " years old.");
}


Jscript from http://msdn.microsoft.com/en-us/library/aa239571(VS.60).aspx

__________________
Post an example, and we will have a much better idea what the problem is. In about 90% of posts, the problem is one of communication. Examples bridge that gap.

PS that's for V6/7 for V9 the problem is V9 at the moment ;)
0
alvittos

New Member
Registered:
Posts: 3
Reply with quote  #20 
My logic is:

If my Birthday 'day of the year' is greater than the current 'day of the year', then deduct a year from my age. If my birthday has happened this year (ie  is <=), do not.

I think that is what my example does?
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:


Create your own forum with Website Toolbox!