RealDocs

UKismetMathLibrary::GetDayOfYear

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

Description

Returns the day of the year for the given date-time, in the range 1–366. Day 1 is January 1st; day 366 only exists in leap years.

Caveats & Gotchas

  • The value is 1-based. January 1 returns 1, not 0. Code that uses this to index into a 0-based array of 365 elements will read out of bounds on day 365 of a non-leap year.
  • Leap years produce values up to 366 — code that assumes a maximum of 365 will be incorrect roughly once every four years. Always use DaysInYear(A.GetYear()) to get the upper bound for the current year.

Signature

static UE_INL_API int32 GetDayOfYear( FDateTime A );

Parameters

Name Type Description Default
A FDateTime The date-time to query.

Return Type

int32

Example

Calculate the fraction of the year elapsed C++
FDateTime Now = FDateTime::UtcNow();
int32 DayNum = UKismetMathLibrary::GetDayOfYear(Now);
int32 TotalDays = FDateTime::IsLeapYear(Now.GetYear()) ? 366 : 365;
float YearProgress = static_cast<float>(DayNum) / static_cast<float>(TotalDays);

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.