Date calculation question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Date calculation question

FernandezLanier, Adriana (DCJS)

Good afternoon. I have two date variables—time released and time enrolled.  They are both in SPPS date format (e.g., 07-Mar-2008). Is there a more direct way to calculate the time difference between the two variables besides using the extraction format to create year, month, and day which would then allow me to use yrmoda function. For example, I would like to calculate the time difference between 07-Mar-2008 and 25-Aug-2006. Any suggestions would be appreciated. Thanks, Adriana

 

P Please consider the environment before printing this e-mail.

 



This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system.
Reply | Threaded
Open this post in threaded view
|

Re: Date calculation question

Marta Garcia-Granero
FernandezLanier, Adriana (DCJS) wrote:
>
> Good afternoon. I have two date variables—time released and time
> enrolled. They are both in SPPS date format (e.g., 07-Mar-2008). Is
> there a more direct way to calculate the time difference between the
> two variables besides using the extraction format to create year,
> month, and day which would then allow me to use yrmoda function. For
> example, I would like to calculate the time difference between
> 07-Mar-2008 and 25-Aug-2006. Any suggestions would be appreciated.
>
COMPUTE TimeDiff=CTIME.DAYS(TimeReleased - TimeEnrolled).

Will give you the result in days.

COMPUTE TimeDiff=CTIME.DAYS(TimeReleased - TimeEnrolled)/7.

Will give you the result in weeks.

Months and years will give an approximate result, since the average
month length could be considered 365.25/12=30.4375, and the average year
length is 365.25 (1 in 4 is a leap - and Olympic - year).

There most certainly will be better ways, but that's the one I use.

HTH,
Marta GG

--
For miscellaneous SPSS related statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Date calculation question

Jon K Peck

If these are actually SPSS date variables, the DATEDIFF function will give exact calendar results in units of your choice.  See the DATEDIFF help for details.

Jon Peck
SPSS, an IBM Company
[hidden email]
312-651-3435



From: GarcĂ­a-Granero <[hidden email]>
To: [hidden email]
Date: 02/18/2010 10:19 AM
Subject: Re: [SPSSX-L] Date calculation question
Sent by: "SPSSX(r) Discussion" <[hidden email]>





FernandezLanier, Adriana (DCJS) wrote:
>
> Good afternoon. I have two date variables—time released and time
> enrolled. They are both in SPPS date format (e.g., 07-Mar-2008). Is
> there a more direct way to calculate the time difference between the
> two variables besides using the extraction format to create year,
> month, and day which would then allow me to use yrmoda function. For
> example, I would like to calculate the time difference between
> 07-Mar-2008 and 25-Aug-2006. Any suggestions would be appreciated.
>
COMPUTE TimeDiff=CTIME.DAYS(TimeReleased - TimeEnrolled).

Will give you the result in days.

COMPUTE TimeDiff=CTIME.DAYS(TimeReleased - TimeEnrolled)/7.

Will give you the result in weeks.

Months and years will give an approximate result, since the average
month length could be considered 365.25/12=30.4375, and the average year
length is 365.25 (1 in 4 is a leap - and Olympic - year).

There most certainly will be better ways, but that's the one I use.

HTH,
Marta GG

--
For miscellaneous SPSS related statistical stuff, visit:
http://gjyp.nl/marta/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Date calculation question

Art Kendall
In reply to this post by FernandezLanier, Adriana (DCJS)
{snipped from <help>
Date Differences <script type="text/javascript" src="ms-its:mainhelp.chm::/chmhelp.js"></script>

Date Differences

date and time functions,date and time functions,date and time functions
difference between dates,difference between dates,difference between dates
DATEDIFF function,DATEDIFF function,DATEDIFF function
functions,functions,functions
date and time,date and time,date and time

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. 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:

• Years

• Quarters

• Months

• Weeks

• Days

• Hours

There is more details under <help>

Art Kendall
Social Research Consultants

On 2/18/2010 12:08 PM, FernandezLanier, Adriana (DCJS) wrote:

Good afternoon. I have two date variables—time released and time enrolled.  They are both in SPPS date format (e.g., 07-Mar-2008). Is there a more direct way to calculate the time difference between the two variables besides using the extraction format to create year, month, and day which would then allow me to use yrmoda function. For example, I would like to calculate the time difference between 07-Mar-2008 and 25-Aug-2006. Any suggestions would be appreciated. Thanks, Adriana

 

P Please consider the environment before printing this e-mail.

 



This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system.
===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants