KB-35784: Displaying values with milliseconds in a Report.

Question:

How can I display values with milliseconds in a Report?

Solution:

For versions equal to or higher than v. 3.5 b. 174, to format the date/time with milliseconds, the report’s DataField property must be set up like this:

=E3Globals.E3Format(E3TimeStamp, “dd/MM/yyyy HH:mm:ss.000”)


For versions lower than v. 3.5 b. 174, use one of the solutions below:

1. Set this calculation in the DataField property of a Report’s Data Field object:

=Right("0" + CStr(Day(Fix((CDbl(E3TimeStamp) + (1.0 / 172800000.0))*86400.0)/86400.0)),2)+"/"+Right("0" +CStr(Month(Fix((CDbl(E3TimeStamp) + (1.0/172800000.0))*86400.0)/86400.0)),2)+"/"+CStr(Year(Fix((CDbl(E3TimeStamp) + (1.0 / 172800000.0))*86400.0)/86400.0))+" "+Right("0" +CStr(Hour(Fix((CDbl(E3TimeStamp)+(1.0 /172800000.0))*86400.0)/86400.0)),2)+":"+String(2-Len(CStr(Minute(Fix((CDbl(E3TimeStamp)+(1.0 /172800000.0))*86400.0)/86400.0))), "0") & CStr(Minute(Fix((CDbl(E3TimeStamp)+(1.0 /172800000.0))*86400.0)/86400.0))+":"+String(2-Len(CStr(Second(Fix((CDbl(E3TimeStamp) + (1.0 /172800000.0))*86400.0)/86400.0))), "0") & CStr(Second(Fix((CDbl(E3TimeStamp) + (1.0 /172800000.0))*86400.0)/86400.0)) + "." +String(3-Len((Round(((((CDbl(E3TimeStamp)+(1/172800000))*86400.0) -Fix((CDbl(E3TimeStamp) + (1/172800000))*86400.0))*1000),0))), "0") & (Round(((((CDbl(E3TimeStamp) +(1/172800000))*86400.0) - Fix((CDbl(E3TimeStamp)+(1/172800000))*86400.0))*1000),0))

2. Another possibility is to leave DataField property empty, and set the following script in the Detail section instead:

Function FormatDateMs(dtDate)
DIM dMSec, dSec, dt

‘ First it converts the date from days into milliseconds
‘ (rounds the milliseconds)

dMSec = Round(CDbl(dtDate) * 86400000)

‘ Gets the number of seconds (discards the milliseconds)
dSec = Fix(dMSec / 1000)

‘ Generates a date again (without the milliseconds)
dt = CDate(dSec / 86400)

‘ Calculates the milliseconds (0 a 999)
dMSec = dMSec – (dSec * 1000)

FormatDateMs = Right(“0” + CStr(Day(dt)), 2) + “/” + _
Right(“0” + CStr(Month(dt)), 2) + “/” + _
CStr(Year(dt)) + ” ” + _
Right(“0” + CStr(Hour(dt)), 2) + “:” + _
Right(“0” + CStr(Minute(dt)), 2) + “:” + _
Right(“0” + CStr(Second(dt)), 2) + “.” + _
Right(“00” + CStr(dMSec), 3)
End Function

Sub OnFormat
‘ Repeats the line below for each Date/Time field that must have the
‘ milliseconds displayed, just changing Field1 for the Field object’s name,
‘ and E3TimeStamp for the field’s name.

Report.Sections(“Detail”).Controls(“Field1”).Text = _
FormatDateMs(Report.Fields(“E3TimeStamp”))
End Sub

NOTE: this example uses the E3TimeStamp field, but you can edit the script to set any other field.

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *