mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2004
Posts: 218
P
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Apr 2004
Posts: 218
Hello, I'm currently just looking for a simple way to calculate the duration between two set dates. Currently mIRC's internal $duration only calculates up to weeks. Though, I'm sure it could easily incorprate months and years since the standard month is 30 days, and a year is standard as 365 days.

I've tryed unseccesfully to produce my own short script to do this, and I'm looking for any suggestions, improvements, etc.

Code:
until { 
  var %duration = $duration($round($calc(($ctime($3 $1 $2 $iif($4,$4 $+ :00,00:00:00)) - $ctime)),2))
  var %until = $1-
  tokenize 32 %duration
  if (*wks iswm $1) && ($remove($1,wks) >= 4) {
    %weeks = $remove($1,wks)
    if (%weeks >= 52) { var %years = $round($calc(%weeks / 52),0) }
    var %months = $calc((%weeks / 4) - (%years * 12))
    var %weeks = $round($calc($chr(26) $+ $gettok(%months,2,46) * 4),0)
  }
  var %duration = %years $+ $iif(%years > 1,yrs,yr) %months $+ $iif(%months > 1,mth,mths) %weeks $+ $iif(%weeks > 1,wks,wk) $remove(%duration,$1)
  say There is %duration until %until 
}


I know it's not the best looking code. :x


Live to Dream & Dream for Life
Joined: Oct 2003
Posts: 214
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 214
Try this:

Code:
; $dur(time in ctime format)
alias dur {
  var %t = 31557600.yr:2629800.mth:604800.wk:86400.day:3600.hr:60.min:1.sec,%i 1,%r,%a $1
  while ($gettok(%t,%i,58)) {
    tokenize 46 $ifmatch
    if (%a >= $1) { var %x = $int($calc(%a / $1)),%r = %r $+(%x,$2,$iif(%x > 1,s)),%a = $calc(%a - ($1 * %x)) }
    inc %i
  }
  return %r
}


Maybe this will help you also.


one step closer to world domination
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can use my $DateXpander identifier if you want. It correctly calculates months and years (even with leap years) and works basically like $duration.

It works by counting backwards in the most basic syntax. So if you give it 33457767 seconds as the time difference, it will calculate from the current time/date backwards that many seconds and tell you that the duration is 1 year, 3 weeks, 1 day, 5 hours, 49 minutes, and 27 seconds. Of course, you can limit the items that show up if you don't want to see the seconds or minutes or whatever. If you were to make it not show years, then it would give you 12 months instead as the beginning of the output rather than just dropping the year part.

$DateXpander(33457767)

You can see the examples on the posts on the link above for different ways you can use it.

Note also that you *can* go into the future by including a start date (you're still counting backwards, so you'd calculate it from that future start date). This is a little more complicated, but it's useful for counting down until a specific date (Christmas, birthday, etc).

This will show the time until Christmas.
//echo -a $DateXpander($calc($ctime(Dec 25 2007 00:00:00) - $ctime),12/25/2007)

Note that the calculation is giving the duration in seconds between today's date and the future date (just like if you gave any other number of seconds to calculate a $duration). The start date is after the comma.


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2004
Posts: 218
P
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Apr 2004
Posts: 218
Thanks for your replies.


Live to Dream & Dream for Life
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Just to spam mine as well smile $datediff


$maybe

Link Copied to Clipboard