RealDocs

UKismetMathLibrary::Subtract_DateTimeDateTime

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintPure

Description

Returns the elapsed time between two FDateTime values as an FTimespan. This is the standard way to measure how much time has passed between two timestamps.

Caveats & Gotchas

  • The result is negative when A is earlier than B — FTimespan supports negative durations. Use FTimespan::GetDuration() to get the absolute value if you only care about the magnitude.
  • Both A and B should be in the same timezone (both UTC or both local time). Mixing UTC and local timestamps will produce a span that's off by the local UTC offset, which is a silent, hard-to-debug error.

Signature

static UE_INL_API FTimespan Subtract_DateTimeDateTime(FDateTime A, FDateTime B);

Parameters

Name Type Description Default
A FDateTime The later (or reference) date and time.
B FDateTime The earlier (or comparison) date and time.

Return Type

FTimespan

Example

Measure elapsed real time C++
FDateTime Start = FDateTime::UtcNow();
// ... some work ...
FDateTime End = FDateTime::UtcNow();
FTimespan Elapsed = UKismetMathLibrary::Subtract_DateTimeDateTime(End, Start);
UE_LOG(LogTemp, Log, TEXT("Elapsed: %.3f seconds"), Elapsed.GetTotalSeconds());

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.