---
title: Encode a DateTime as a Julian string
summary: Encode a DateTime as a Julian-format string.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
operation_id: OP-009
trigger: Caller produces a Julian-formatted date for file interchange*
---

# Encode a DateTime as a Julian string

Encode a DateTime as a Julian-format string, triggered when caller produces a Julian-formatted date for file interchange*.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-009 |
| **Trigger** | Caller produces a Julian-formatted date for file interchange* |
| **Inputs** | `date`, `yearLength` |
| **Outputs** | `string` |
| **Primary components** | ``Julian.ToJulian(this DateTime date, int yearLength = 2)`` |
| **Entry point** | `Common/SAIF.Common/Classes/Julian.cs` |

## Steps

1. If `yearLength == 2`, format the year as `"yy"` and convert to `Int32` (dropping any leading zero); otherwise use the full four-digit `date.Year`. ([BR-027](<../business-rules.md#br-027-a-julian-string-is-encoded-as-the-year-(2-digit-by-default%2C-4-digit-on-request)-followed-by-the-zero-padded-3-digit-day-of-year>))
2. Format `date.DayOfYear` with the `"000"` mask so it is always three digits. ([BR-027](<../business-rules.md#br-027-a-julian-string-is-encoded-as-the-year-(2-digit-by-default%2C-4-digit-on-request)-followed-by-the-zero-padded-3-digit-day-of-year>))
3. Concatenate year + day and return.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["Caller requests Julian<br>date encoding"]) --> Check{"yearLength == 2?"}
	Check -->|Yes| Y2["Format year as 'yy'<br>convert to Int32"]
	Check -->|No| Y4["Use full four-digit<br>date.Year"]
	Y2 --> Day["Format DayOfYear<br>with '000' mask"]
	Y4 --> Day
	Day --> Concat["Concatenate year + day"]
	Concat --> End([Return Julian string])
```

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

## Sources
- `Common/SAIF.Common/Classes/Julian.cs`
