Top

$datediff


mIRC Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  8.0 (of 2 scores)
Date Added  Oct 13, 2006
Last Updated  Nov 15, 2006
Tags  birthday  date  duration  months  weeks  years 

Introduction

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.

Grab the Code

/*
$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

  (8)  RSS
Cherish
Comments: 11
 
mIRC Snippet:  $datediff
Posted on Oct 15, 2006 3:01 am
ERROR COM
* No such Com 'dd916111' open (line 60, script7.mrc)
Mpdreamz
Comments: 44
 
mIRC Snippet:  $datediff
Posted on Oct 15, 2006 4:36 am
oops forgot a return there. What windows version are you using ?
Cherish
Comments: 11
 
mIRC Snippet:  $datediff
Posted on Oct 15, 2006 2:53 pm
Microsoft Windows 98 (version: 4.10.1998) :D
Mpdreamz
Comments: 44
 
mIRC Snippet:  $datediff
Posted on Oct 22, 2006 4:01 am
Thought so :)
The Com object i use is only for ME/2000 or higher I am working on a 98 compliant version using wscript.shell but involves writing a vbs file to your machine and setting an environment variable on your machine something virus scanners might not like so therefore windows 98 support will be tacky :P
Cherish
Comments: 11
 
mIRC Snippet:  $datediff
Posted on Nov 3, 2006 11:56 am
Ok.. But dd/mm/yy I think is better becouse $date, $fulldate and other identifers use it.
QuickStep
Comments: 123
 
mIRC Snippet:  $datediff
Posted on Nov 3, 2006 12:19 pm
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.
Mpdreamz
Comments: 44
 
mIRC Snippet:  $datediff
Posted on Nov 14, 2006 5:31 pm
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.
Mpdreamz
Comments: 44
 
mIRC Snippet:  $datediff
Posted on Nov 14, 2006 5:44 pm
Cherish it will accept any VB date :)

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom