If you want a datelike form, you can compute the parts using the mod function, e.g., However, that is not itself a date: it is a duration and, therefore, would not have a date format. So that matches the age calculation that applies if you are trying to buy a drink or get a driver's license. One "month" is defined as the same day of the month, one calendar month before or after the second date argument.ĭATEDIFF will give you the exact difference in the requested units with truncation.The result will be the integer portion of the number of months between the two dates, with any fractional component truncated.For the third case, the result is 0, since the difference is one day short of a year based on the definition of year.ĬOMPUTE months=DATEDIFF(date2, date1, "months").For the first two cases, the result is 1, since in both cases the number of years is greater than or equal to 1 and less than 2.One "year" is defined as the same month and day, one year before or after the second date argument.The result will be the integer portion of the number of years between the two dates, with any fractional component truncated.The general form of the expression is DATEDIFF(datetime2, datetime1, "unit") where datetime2 and datetime1 are both date or time format variables (or numeric values that represent valid date/time values), and "unit" is one of the following string literal values, enclosed in quotes:ĬOMPUTE years=DATEDIFF(date2, date1, "years"). The DATEDIFF function calculates the difference between two date values and returns an integer (with any fraction component truncated) in the specified date/time units. Here is an excerpt from the Command Syntax Reference manual: Does anyone know how I would write the syntax to get this to work?. So I thought maybe I could add 30 days to the day variable and minus 1 for the month when the day is a minus answer, or, add 12 to the month variable and minus 1 for the year when the month is a minus answer. The chronological age variable I need assumes that all months have 30 days in them. clinic in janurary and dob in july (1-7=-6). I thought I'd cracked it until realising I had minus answers from dates that had months or days smaller for the clinic date e.g. I then minused these variables from each other to find the time between. So I made 3 new variables from each date variable made up of the day, month and year. However, I need the format of the age in years, months and days between the two dates. I have used this syntax to get a numeric age: compute agechr=(aw2 - dob) / (365.25 * time.days(1)). I'm trying to make a new variable which will be the age at a time point (clinic date and dob).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |