$datediff

By Mpdreamz on Oct 13, 2006

The purpose of this snippet is to bring the power of VB's DateDiff function to mIRC which date handling functions can be quite restricting.
This snippet allows you to calculate the difference between ANY date in whatever timespan you specify so you can easily check how many days have passed since Washington became president which is 79423 days at the time of writing this :). It also allows you to easily do birthday bots and seen scripts that cover years in duration.

/*
$datediff
#Contact information: This snippet was written by Mpdreamz and is free to use as you please however claiming it as your own is deprecated. 
You can always contact me at Mpdreamz [at] gmail.com or leave a message at the site you downloaded this from.

#How to load this alias
Copy paste this alias somewhere in your remote, preferably at top first or last line.

#Purpose: The purpose of this snippet is to bring the power of VB's DateDiff function to mIRC which date handling functions can be quite restricting.
This snippet allows you to calculate the difference between ANY date so you can easily check how many days have passed since Washington became president
which is 79423 days at the time of writing this :). It also allows you to easily do birthday bots and seen scripts that cover years in duration.

#Syntax: $datediff(startdate[,enddate],formatting parameters)[.[s][e]]
startdate: is a date value formatted as mm/dd/yyyy so for example 30/04/1789
enddate: is a date value formatted as mm/dd/yyyy and is not manditory. If not specified the current date will be used.
formatting parrameters: This can be any of the following
y=Years
q=Quarters
m=Months
w=Weeks
d=Days
h=Hours
n=Minutes
s=Seconds
a=Use all

This snippet returns a space delimited token list of the formatting parameters you specified in order of highest timespan till lowest.
For example dw will returns <Number of weeks> <Number of days> eventhough d is specified before w
Its important to remember that these parameters should all touch i.e no spaces between them.
specifying the s in the property will strip the named suffixes.
Using the e in the property returns the total ammount for each format parameter specified

#Examples:
//echo -a $datediff(30/04/1789,d)
Number of days since the first american president ;)
//echo -a $datediff(01/01/2004,31/12/2005,wdy)
returns 1year 52weeks 0days
//echo -a $datediff(01/01/2004,31/12/2005,wdy).e
returns 1year 104weeks 730days because the time in between is 1 whole year or 104 whole weeks or 730 whole days
//echo -a $datediff(01/01/2004,31/12/2005,wdy).s
returns 1 52 0
//echo -a $datediff(01/01/2004,31/12/2005,wdy).se
returns 1 104 730
Dont forget you can also specify times ! :)
//echo -a $datediff(01/01/1904 10:15:12,31/12/2005 20:20:14,a)
returns 101years 3quarters 2months 4weeks 2days 10hours 5minutes 1second

#Shoutouts
FiberOPtics for paving the way, your a true pioneer bro :)
And everyone i met trough mIRCscripts, you know who you are! ;)
Enjoy!
*/
alias datediff {
  var %t,%result,%n = $crlf , %com = dd $+ $ticks, %s = $iif($3,$qt($1),Date) , %e = $qt($iif($3,$2,$1)), %values = $($+($,$0),2), $&
    %error = $regex(%values,/[^yqmwadhns]/g), %values = $gettok($regsubex(%values,/([yqmwdhnsa])/g,$+(\t,$chr(44))),1-,44), $&
    %right = y,q,m,w,d,h,n,s, %values = $iif(a !isin %values,$gettok($remove(%right, [ $remove(%right, [ %values ] ) ] ),1-,44),%right)
  if ($istok(95 98,$os,32)) return E_OS
  if (%error) return E_FORMAT
  %t = Dim sd,ed,ret, $+ %values %n sd = %s %n ed = %e %n If isDate(sd) AND isDate(ed) Then %n
  tokenize 44 %values
  while ($0) {
    %t = %t $1 = DateDiff( $qt($replace($upper($1),y,YYYY)) ,sd,ed) %n
    if (e !isin $prop) %t = %t sd = DateAdd( $qt($replace($upper($1),y,YYYY,w,ww)) , $1 ,sd) %n
    tokenize 32 $2-
  }
  %t = %t ret = $replace(%values,$chr(44),$+($chr(32),&,,$chr(32)," ",,$chr(32),&,$chr(32))) %n Else ret = "E_DATE" %n End If
  .comopen %com MSScriptControl.ScriptControl
  if ($comerr) return E_COM
  noop $com(%com,language,4,bstr*,vbscript)
  if ($com(%com,executestatement,1,bstr*,%t)) && ($com(%com,eval,3,bstr*,ret )) %result = $com(%com).result
  else return = E_VB
  :error
  if ($com(%com)) .comclose %com $com(%com,reset,1)
  if ((E_* iswm %result) || (s isin $prop)) return %result
  else return $regsubex($replacex($regsubex(%result,/(\d+)/g,$+(\t,$gettok(%values,\n,44))),y,years,m,months,q,quarters,w,weeks,d,days,h,hours,n,minutes,s,seconds),/(?<!\d)(1[a-z]+?)s/g,\t)
}

Comments

Sign in to comment.
Mpdreamz   -  Nov 14, 2006

Cherish it will accept any VB date :)

 Respond  
Mpdreamz   -  Nov 14, 2006

True however this wont just return seconds, but also months quarters and years something which would take alot of mirc $calcing power and would run rather slow on big numbers.

 Respond  
QuickStep   -  Nov 03, 2006

Theoratically this isn\'t all that hard to do in mIRC script. A normal year contains 31536000 seconds and a leapyear 31622400 seconds. Rest is just basic calculations.

 Respond  
Cherish   -  Nov 03, 2006

Ok.. But dd/mm/yy I think is better becouse $date, $fulldate and other identifers use it.

 Respond  
Cherish   -  Oct 15, 2006

Microsoft Windows 98 (version: 4.10.1998) :D

 Respond  
Cherish   -  Oct 15, 2006

ERROR COM

  • No such Com \'dd916111\' open (line 60, script7.mrc)
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.