mIRC Home    About    Download    Register    News    Help

Print Thread
#131954 06/10/05 09:57 AM
Joined: Feb 2005
Posts: 342
R
Rand Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Alright, since my brain doesn't seem to be functioning tonight, I've been struggling with a script.

This script *should* tell me how many years/months/days/hours/minutes has passed since <x> time.

I can do this, but not reliably.

Code:
alias elapsed_time {
  var %otime = $ctime($1-4) , %ntime = $ctime($5-8)
  var %seconds = $calc( %ntime - %otime )
  var %minutes = $calc( %seconds / 60 )
  var %hours = $calc( %minutes / 60 )
  var %days = $calc( %hours / 24 )
  var %lohours = $calc( %hours % 24 )
  var %lomins = $calc( %minutes % 60 )
  var %losecs = $calc( %seconds % 60 )
  echo -stg Days: $int(%days) $+ , Hours: $int(%lohours) $+ , Minutes: $int(%lomins) $+ , Seconds: $int(%losecs)
}


ie:
/elapsed_time October 6th 2004 05:00:00am October 6th 2005 05:00:00pm

would return: Days: 365, Hours: 12, Minutes: 0, Seconds: 0

Now.. the problem would be doing months->years, as the days in months vary, so I wouldn't be able to do: var %months = $calc( %days / 30 )

So, does anyone know of any other way I could figure out how many months have passed?

#131955 06/10/05 11:11 AM
A
Anonymous
Unregistered
Anonymous
Unregistered
A
if it's some script where users get to enter the date you could try:
Code:
 
alias elapsed_time {
 var %firstdate = $$?="Enter the first date in format day/month/year hh:mm:ss  : "
 var %seconddate = $$?="Enter the second date in format  day/month/year hh:mm:ss  : "
 echo -a Time between the 2 dates is: $duration($calc($ctime(%seconddate) - $ctime(%firstdate)))
}
 


to test it just enter the first time:
20/05/2006 21:23:34
and the second time:
20/06/2006 10:44:21

Last edited by filip_xyz; 06/10/05 11:12 AM.
#131956 06/10/05 11:11 AM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Riamus made this snippet to do exactly what you want smile
http://www.mircscripts.org/comments.php?cid=2861


$maybe
#131957 06/10/05 12:29 PM
Joined: Feb 2005
Posts: 342
R
Rand Offline OP
Fjord artisan
OP Offline
Fjord artisan
R
Joined: Feb 2005
Posts: 342
Quote:
if it's some script where users get to enter the date you could try:
Code:
 
alias elapsed_time {
 var %firstdate = $$?="Enter the first date in format day/month/year hh:mm:ss  : "
 var %seconddate = $$?="Enter the second date in format  day/month/year hh:mm:ss  : "
 echo -a Time between the 2 dates is: $duration($calc($ctime(%seconddate) - $ctime(%firstdate)))
}
 


to test it just enter the first time:
20/05/2006 21:23:34
and the second time:
20/06/2006 10:44:21


That's not what I wanted. As I pointed out above, I can do the days / minutes / hours / seconds, by using what I have. Can easily add weeks, but I didn't really find it necessary to use. I just put these in variables, so that I can pick and choose what I need when I need it. I would use $duration() as you have, except I wanted a bit more control of what it's doing. I dislike dealing with popup-input boxes, too.

Quote:
Riamus made this snippet to do exactly what you want smile
http://www.mircscripts.org/comments.php?cid=2861


Thanks, I'll check it out.

#131958 06/10/05 01:24 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Heh! I'm famous! LOL! grin

**If anyone uses it, it's updated as of yesterday, just so you know.

Anyhow, Rand... my script will do what you want. To use it for what you're trying to do, here's the format you'd want to use:

//echo -a $DateXpander($calc($ctime - $ctime(Aug 27 1978 00:00)))

Hm... I'm getting old... smile

Ok, this seems more complicated because of needing to calculate the duration you need. You could set a variable...

var %duration = $calc($ctime - $ctime(Aug 27 1978 00:00))
echo -a $DateXpander(%duration)

Note that if you don't want to go back from today's date, you can replace $ctime with $ctime(date time) using the same format as the second half of that $calc. If you do this, you MUST include the "startdate".

Here's an example:

var %duration = $calc($ctime(Jan 19 2009 5:14) - $ctime(Aug 27 1978 00:00))
echo -a $DateXpander(%duration,01/19/2009)

One final note... if you already know the duration (in seconds or in the $duration format), then you just need to insert that into the $DateXpander identifier without using the $calc part.

If you have any questions, just ask on mircscripts.org or here. laugh


Invision Support
#Invision on irc.irchighway.net
#131959 06/10/05 01:37 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
And, if you want it to work from an alias like you mentioned (or even a trigger), you can do this:

Code:
alias elapsed_time {
  if ($8 != $null) {
    var %duration = $calc($ctime($1-4) - $ctime($5-8))
    echo -a $DateXpander(%duration,$asctime($ctime($5-7),mm/dd/yyyy)
  }
  elseif ($7 == $null &amp;&amp; $6 != $null) {
    var %duration = $calc($ctime($1-3) - $ctime($4-6))
    echo -a $DateXpander(%duration,$asctime($ctime($4-6),mm/dd/yyyy)
  }
}


The part after the comma in $DateXpander gives you the startdate formatted correctly. For this to work as it's written, you need to use the same format you mentioned...

/elapsed_time October 6th 2004 05:00:00am October 6th 2005 05:00:00pm

If you change the format, then you need to change the alias to work with the different format(s) that you want to use. Note that if your highest date is the second date in the alias, then you use $5-7 (and $4-6)... if it's the first date used, then you need to use $1-3 instead, or it will not work properly.

I've made that alias to allow you to use:
/elapsed_time October 6th 2004 05:00:00am October 6th 2005 05:00:00pm

and

/elapsed_time October 6th 2004 October 6th 2005

(in case you just want duration between dates and not date/time). Beyond that, you'd have to change the format of the alias.

If you need help, just ask.


Invision Support
#Invision on irc.irchighway.net
#131960 07/10/05 01:07 PM
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Read this thread too, it was the birth of more date scripts smile


Link Copied to Clipboard