mIRC Date & Time Comparison

By Screaming Fist on Aug 01, 2015

I was searching for a quick way to compare two date & times to determine which was newer but was unable to find anything easily modifiable. I cobbled this code together and it seems to work just fine. I'm sure there is a better way to do it but I am pretty new to this. Any questions or suggestions please let me know.

; Date & Time Comparison
; Syntax: $dtcompare(yyyy-mm-dd,hh:mm:ss,yyyy-mm-dd,hh:mm:ss)
; Returns 1 for the first set being newer, 2 for the second set being newer or 3 for both being the same
alias dtcompare {
  if (!$isid) {
    return
  }
  var %winner

  var %year1 = $mid($1,1,4)
  var %month1 = $mid($1,6,2)
  var %day1 = $mid($1,9,2)
  var %hour1 = $mid($2,1,2)
  var %min1 = $mid($2,4,2)
  var %sec1 = $mid($2,7,2)

  var %year2 = $mid($3,1,4)
  var %month2 = $mid($3,6,2)
  var %day2 = $mid($3,9,2)
  var %hour2 = $mid($4,1,2)
  var %min2 = $mid($4,4,2)
  var %sec2 = $mid($4,7,2)

  if (%year1 > %year2) {
    %winner = 1
  }
  elseif (%year1 < %year2) {
    %winner = 2
  }
  elseif (%month1 > %month2) {
    %winner = 1
  }
  elseif (%month1 < %month2) {
    %winner = 2
  }
  elseif (%day1 > %day2) {
    %winner = 1
  }
  elseif (%day1 < %day2) {
    %winner = 2
  }
  elseif (%hour1 > %hour2) {
    %winner = 1
  }
  elseif (%hour1 < %hour2) {
    %winner = 2
  }
  elseif (%min1 > %min2) {
    %winner = 1
  }
  elseif (%min1 < %min2) {
    %winner = 2
  }
  elseif (%sec1 > %sec2) {
    %winner = 1
  }
  elseif (%sec1 < %sec2) {
    %winner = 2
  }
  else {
    %winner = 3
  }
  return %winner
}

Comments

Sign in to comment.
Vegito   -  Aug 06, 2015

You can use the $ctime(text) identifier to compare dates.
$ctime uses standard Unix timestamps, which are the seconds elapsed since midnight, January 1, 1970 to your specified date.

The only downside is that you can only compare dates from January 1, 1970 to January 19, 2038.

alias comparedate {
  if ($ctime($1) > $ctime($2)) return 1
  elseif ($ctime($1) < $ctime($2)) return 2
  else return 3
}
 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.