Index: /trunk/tools/czartool/MySQLDb.pm
===================================================================
--- /trunk/tools/czartool/MySQLDb.pm	(revision 29749)
+++ /trunk/tools/czartool/MySQLDb.pm	(revision 29750)
@@ -131,5 +131,21 @@
 ###########################################################################
 #
+# Formats a date/time string in a way suitable for TIMEDIFF calls
+#
+###########################################################################
+sub formatTimeForDiff {
+    my ($self, $time) = @_;
+
+    if (${$time} =~ m/^[0-9]{4}-[0-9]{2}-[0-9]{2}.*/) {${$time} = $self->getFullDate(${$time});}
+    elsif(${$time} !~ m/^[0-9]+:[0-9]{2}:[0-9]{2}$/) {return 0;}
+
+    return 1;
+}
+
+###########################################################################
+#
 # Finds the difference of two times
+#
+# Should be able to handle most date/time formats
 #
 ###########################################################################
@@ -139,4 +155,6 @@
     if (!$time1 || !$time2) {return 0;}
 
+    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
+
     my $query = $self->{_db}->prepare(<<SQL);
          SELECT TIMEDIFF('$time1','$time2'); 
@@ -174,4 +192,5 @@
 
     if (!$time1 || !$time2) {return 0;}
+    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
 
     my $query = $self->{_db}->prepare(<<SQL);
@@ -207,10 +226,13 @@
     my ($self, $time1, $time2) = @_;
 
-      my $query = $self->{_db}->prepare(<<SQL);
-          SELECT TIME_TO_SEC(TIMEDIFF('$time1', '$time2'));
-SQL
-    $query->execute;
-
-return (scalar $query->fetchrow_array() > 0) ? 0 : 1;
+    if (!$time1 || !$time2) {return 0;}
+    if (!$self->formatTimeForDiff(\$time1) || !$self->formatTimeForDiff(\$time2)) {return 0;}
+
+    my $query = $self->{_db}->prepare(<<SQL);
+    SELECT TIME_TO_SEC(TIMEDIFF('$time1', '$time2'));
+SQL
+    $query->execute;
+
+    return (scalar $query->fetchrow_array() >= 0) ? 0 : 1;
 }
 
