Skip to content

SpanDays

See Also: Time and Date Functions

Purpose

The SpanDays function returns the Days component of the given TimeSpan variable field, tsVar.

Return Type

Integer

The SpanAddXxx functions differ from the SpanXxx functions, which do not perform TimeSpan arithmetic (i.e., they just set one TimeSpan section) and neither the incoming nor outgoing TimeSpan variable is tested for validity.

In most cases, the SpanAddXxx functions (SpanAddDay, SpanAddHour, SpanAddMillisecond, SpanAddMinute, SpanAddSecond) can be used in preference to the SpanXxx functions (SpanDays, SpanHours, SpanMilliseconds, SpanMinutes, SpanSeconds). The SpanXxx functions are lower level and should be rarely used.

Syntax

SpanDays(tsVar)

Example

This sample shows the total time that has passed since 12/31/2007 at one second before midnight.

Procedure TestSpanMilliSeconds
    DateTime dtVar1 dtVar2
    TimeSpan tsVar

    // Set dtVar1 to 12/31/2007, 11:59:59.01 PM
    Move (DateSetYear(dtVar1, 2007)) to dtVar1
    Move (DateSetMonth(dtVar1, 12)) to dtVar1
    Move (DateSetDay(dtVar1, 31)) to dtVar1
    Move (DateSetHour(dtVar1, 23)) to dtVar1
    Move (DateSetMinute(dtVar1, 59)) to dtVar1
    Move (DateSetSecond(dtVar1, 59)) to dtVar1
    Move (DateSetMillisecond(dtVar1, 10)) to dtVar1
    Move (CurrentDateTime()) to dtVar2
    Move (dtVar1 - dtVar2) to tsVar

    Showln "The time passed between " dtVar1 " and " dtVar2 " is"
    Show (SpanDays(tsVar)) " days, "
    Show (SpanHours(tsVar)) " hours, "
    Show (SpanMinutes(tsVar)) " minutes, "
    Show (SpanSeconds(tsVar)) " seconds and "
    Showln (SpanMilliseconds(tsVar)) " milliseconds"
End_Procedure

Notes

To find the total number of days between two DateTime variables, use the SpanTotalDays function.