+ Reply to Thread
Results 1 to 2 of 2

Thread: Functions for calculating time between 2 variables

  1. #1
    Points: 403, Level: 8
    Level completed: 6%, Points required for next Level: 47

    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Functions for calculating time between 2 variables



    Hello,

    I have a large data set, and, in the data set, there are a number of dates entered as string variables (e.g., 05SEP2012).

    I need to determine the length of time in years between some of these variables (e.g., from 20MAR1969 to 05SEP2012), but can't seem to figure it out. I have tried a few things under the compute variable functions and date and time wizard but haven't had success. Data set way too large to calculate manually.

    Any ideas/suggestions?

    Thanks,
    L

  2. #2
    Points: 1,494, Level: 21
    Level completed: 94%, Points required for next Level: 6

    Posts
    70
    Thanks
    0
    Thanked 27 Times in 25 Posts

    Re: Functions for calculating time between 2 variables


    Here you go (assumes first date variable is named 'date1' and second is 'date2'):


    Code: 
    str #date1 #date2 (a11).
    comp #date1=concat(substr(date1,1,2),"/",substr(date1,3,3),"/",substr(date1,6,4)).
    comp #date2=concat(substr(date2,1,2),"/",substr(date2,3,3),"/",substr(date2,6,4)).
    comp newdate1=number(#date1,date11).
    comp newdate2=number(#date2,date11).
    formats newdate1 newdate2 (date11).
    comp difference=datediff(newdate2, newdate1, "years").
    exe.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats