mIRC Home    About    Download    Register    News    Help

Print Thread
#120343 17/05/05 12:54 AM
Joined: Mar 2005
Posts: 46
P
Pariah Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Mar 2005
Posts: 46
Well I have this script that lets me store user's date of birth, and i've added this code below to return the age difference between users, but it isnt working correctly and i was hoping one of you kind folks would be able to help me out.
Code:
 if ($1 == !agediff) {
  if ($ini(dob.ini,dob,$2)) {
    set %agenick1 $2
    set %dob1 $readini(dob.ini,dob,%agenick1)      
    if ($ini(dob.ini,dob,$3)) {
      set %agenick2 $3
      set %dob2 $readini(dob.ini,dob,%agenick2)
      if ($ctime(%dob1) > $ctime(%dob2)) {
        %a = $ctime(%dob1) - $ctime(%dob2)
        %years = %a / 31556952
        %div = %a % 31556952
        %months = %div / 2629746
        %days = $int($calc((%div % 2629746)/86400))
        msg $chan %agenick1 is $int(%years) years, $int(%months) months, %days days, older than %agenick2
        unset %agenick*
        unset %dob*
      }
      else {
        %a = $ctime(%dob2) - $ctime(%dob1)
        %years = %a / 31556952
        %div = %a % 31556952
        %months = %div / 2629746
        %days = $int($calc((%div % 2629746)/86400))
        msg $chan %agenick1 is $int(%years) years, $int(%months) months, %days days, younger than %agenick2
        unset %agenick*
        unset %dob*
      }
    }
    else { 
      notice $nick I do not know $+($3,'s) date of birth.
      unset %dob*
      unset %agenick*
    }
  }
  else { 
    notice $nick I do not know $+($2,'s) date of birth.
    unset %dob*
    unset %agenick*
  }
} 

#120344 17/05/05 03:21 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
One problem that you may be encountering is the fact that $ctime doesn't work with dates before Jan 1 1970. If you could tell me the format that the dates are being stored in, in the ini file, I can write you up a new code that will allow for dates before Jan 1 1970.

#120345 17/05/05 09:44 AM
Joined: Mar 2005
Posts: 46
P
Pariah Offline OP
Ameglian cow
OP Offline
Ameglian cow
P
Joined: Mar 2005
Posts: 46
hey thanks for the reply russel, they are stored in a dd/mm/yyyy format in the ini file, I tried to make it work with $adate since that returns an american style of date, but I was never able to make it work like that so I had to stick with the other one.

INI Layout
Code:
[DOB]
user1=30/01/1980
user2=19/08/1990

Last edited by Pariah; 17/05/05 10:02 AM.
#120346 17/05/05 12:48 PM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I don't have an appropriate ini file to be able to test this, but I think this should work. Give it a try and let me know.
Code:
 alias fmtdur { 
  ; Usage: $fmtdur(secs [, format])  
  ; Formatting: [y year] [m month] [w week] [d day] [h hour] [n minute] [s second] [u units]  
  ; Using the same character consecutively will zeropad that unit to the given length (ie. n = 7, nnn = 007)  
  ; Doubling the u character will cause it to use the full format (ie. nu = 6mins, nuu = 6minutes)  
  ; Uppercase U characters will capitalize units. 
  var %fmt = $iif($2,$2,wu du hu nu su), %secs = $int($1), %count = $regex(fmtdur, %fmt, /(([^ymwdhns]*)(y+|m+|w+|d+|h+|n+|s+)([^ymwdhnsUu]*)([Uu]*))/g)  
  var %yrs, %mnths, %wks, %days, %hrs, %mins, %i = 1, %fmtchars, %unitchars, %durstr, %amount, %units 
  if (y isincs %fmt) { %yrs = $int($calc(%secs / 31557600)) | %secs = $calc(%secs % 31557600) }  
  if (m isincs %fmt) { %mnths = $int($calc(%secs / 2629800)) | %secs = $calc(%secs % 2629800) }  
  if (w isincs %fmt) { %wks = $int($calc(%secs / 604800)) | %secs = $calc(%secs % 604800) }  
  if (d isincs %fmt) { %days = $int($calc(%secs / 86400)) | %secs = $calc(%secs % 86400) }  
  if (h isincs %fmt) { %hrs = $int($calc(%secs / 3600)) | %secs = $calc(%secs % 3600) }  
  if (n isincs %fmt) { %mins = $int($calc(%secs / 60)) | %secs = $calc(%secs % 60) } 
  while %i <= $calc(%count * 5) { 
    %fmtchars = $regml(fmtdur, $calc(%i + 2))    
    %unitchars = $regml(fmtdur, $calc(%i + 4))    
    %amount = $charpad($replace($left(%fmtchars, 1),y,%yrs,m,%mnths,w,%wks,d,%days,h,%hrs,n,%mins,s,%secs), $len(%fmtchars), 0)    
    if (u isin %unitchars) { 
      if ($len(%unitchars) == 1) %units = $replacex($left(%fmtchars,1),y,yr,m,mth,w,wk,d,dy,h,hr,n,min,s,sec)      
      else %units = $replacex($left(%fmtchars,1),y,year,m,month,w,week,d,day,h,hour,n,minute,s,second)      
      if (%amount != 1) %units = $+(%units, s)      
      if (U isincs %unitchars) %units = $+($upper($left(%units,1)), $right(%units,-1))    
    } 
    else %units = $null    
    %durstr = $+($left(%durstr, -1), $regml(fmtdur, $calc(%i + 1)), %amount, $regml(fmtdur, $calc(%i + 3)), %units, x))    
    inc %i 5  
  } 
  return $left(%durstr, -1) 
} 
on *:text:!agedif*:*:{
  if !$2 || !$3 {    .msg $nick Sorry, I can't find a birthday for no one }
  elseif !$readini(dob.ini,dob,$2) {      .msg $nick Sorry, I can't find a birthday for $2 }
  elseif !$readini(dob.ini,dob,$3) {      .msg $nick Sorry, I can't find a birthday for $3  }
  elseif $readini(dob.ini,dob,$2) == $readini(dob.ini,dob,$3) {    .msg $nick $2 & $3 have the same birthdays }
  else {
    var %year.1 = $right($readini(dob.ini,dob,$2)), %year.2 = $right($readini(dob.ini,dob,$3))
    while %year.1 < 1970 {
      if $calc(%year.1 / 4) == $int($calc(%year.1 / 4)) {        inc %dob.1 86400     }
      inc %year.1
    }
    while %year.2 < 1970 {
      if $calc(%year.2 / 4) == $int($calc(%year.2 / 4)) {        inc %dob.2 86400     }
      inc %year.2
    }
    inc %dob.1 $ctime($+($left($readini(dob.ini,dob,$2),-4),1970,$chr(32),00:00:00))
    inc %dob.2 $ctime($+($left($readini(dob.ini,dob,$3),-4),1970,$chr(32),00:00:00))
  }
  if %dob.1 > %dob.2 {
    .msg $nick $2 is $fmtdur($calc(%dob.1 - %dob.2),yruu mthuu wkuu dyuu) older than $3
  }
  else {
    .msg $nick $3 is $fmtdur($calc(%dob.2 - %dob.1),yruu mthuu wkuu dyuu) older than $2
  }
}
 


If you want to change the format of the output, all the information that you need (I hope) is in the alias


Link Copied to Clipboard