It's hard to say what works wrong in your code. I advise to use function Int() instead Number(Format()). Also you can use debugger for finding trouble.
I wrote similar code, it works
Code
Minutes = Int((ThisObject.AttributeDate - CurrentDate()) / 60);
If Minutes < 0 Then
ThisObject.AttributeString = "OK";
EndIf;
I suggest the most easiest solution, that I could find.
1. Create information register "RemainingTime"
2. Check flag "Custom Query" in the list form of the document
3. Open "list setup" (hyperlink under checkbox) and modify query text
4. Put new column "Time" on the form
5. Create scheduled task for filling register "RemainingTime" Check flags "Use" and "Predefined" for scheduled task Setup schedule: Perform: every day; every 60 second Check flags "Server" and "Plivileged" for common module "ScheduledJobsServer"
Code of the task:
Code
Procedure UpdateRemainingTime() Export
Now = CurrentDate();
Query = New Query;
Query.Text =
"SELECT
| Document3.Ref,
| Document3.AttributeDate
|FROM
| Document.Document3 AS Document3
|WHERE
| Document3.AttributeDate > &CurrentDate";
Query.SetParameter("CurrentDate", Now);
QueryResult = Query.Execute().Select();
RecordSet = InformationRegisters.RemainingTime.CreateRecordSet();
While QueryResult.Next() Do
Record = RecordSet.Add();
Record.Document = QueryResult.Ref;
Record.Time = GetRemainingTimeText(QueryResult.AttributeDate, Now)
EndDo;
RecordSet.Write();
EndProcedure
Function GetRemainingTimeText(AttributeDate, Now) Export
Minutes = Int((AttributeDate - Now) / 60);
Hours = Int(Minutes / 60);
Days = Int(Hours / 24);
Minutes = Minutes - 60 * Hours;
Hours = Hours - 24 * Days;
Result = "";
If Days > 0 Then
Result = Result + " " + Days + " days"
EndIf;
If Hours > 0 Then
Result = Result + " " + Hours + " hours"
EndIf;
If Minutes > 0 Then
Result = Result + " " + Minutes + " minutes"
EndIf;
Result = Result + " left";
Return Result;
EndFunction
Note, in file mode tasks start two minutes after session start.
6. Enjoy result
7. Also you can add this code in the document's module for instant upd ate when you save document
Code
Procedure OnWrite(Cancel)
RecordSet = InformationRegisters.RemainingTime.CreateRecordSet();
RecordSet.Filter.Document.Set(Ref);
Now = CurrentDate();
If AttributeDate > Now Then
Record = RecordSet.Add();
Record.Document = Ref;
Record.Time = ScheduledJobsServer.GetRemainingTimeText(AttributeDate, Now)
EndIf;
RecordSe t.Write();
EndProcedure