Skip to main content
Version: 3.0.8

Humanizer.DateToOrdinalWordsExtensions

DateToOrdinalWordsExtensions Class

Humanizes DateTime into human readable sentence

public static class DateToOrdinalWordsExtensions

Inheritance System.Object → DateToOrdinalWordsExtensions

Methods

DateToOrdinalWordsExtensions.ToOrdinalWords(this DateOnly) Method

Converts a System.DateOnly to its ordinal words representation (e.g., "1st of January, 2023").

public static string ToOrdinalWords(this System.DateOnly input);

Parameters

input System.DateOnly

The date to be converted to ordinal words.

Returns

System.String
A string containing the date expressed in ordinal words format, culture-specific. For English: "1st of January, 2023", "22nd of December, 2020", etc.

Example

new DateOnly(2023, 1, 1).ToOrdinalWords() => "1st of January, 2023" (in en-US culture)
new DateOnly(2020, 12, 22).ToOrdinalWords() => "22nd of December, 2020" (in en-US culture)

Remarks

The format and style of ordinal words depends on the current culture. Uses the configured date-only-to-ordinal-words converter for conversion. This method is available only on .NET 6.0 and later.

DateToOrdinalWordsExtensions.ToOrdinalWords(this DateOnly, GrammaticalCase) Method

Converts a System.DateOnly to its ordinal words representation using the specified grammatical case.

public static string ToOrdinalWords(this System.DateOnly input, Humanizer.GrammaticalCase grammaticalCase);

Parameters

input System.DateOnly

The date to be converted to ordinal words.

grammaticalCase GrammaticalCase

The grammatical case to use for the output words (e.g., Nominative, Genitive, etc.). This is particularly important for languages with case systems like Russian, Polish, etc.

Returns

System.String
A string containing the date expressed in ordinal words format in the specified grammatical case.

Example

// In Russian culture:
date.ToOrdinalWords(GrammaticalCase.Nominative) => different form than
date.ToOrdinalWords(GrammaticalCase.Genitive)

Remarks

The grammatical case parameter is primarily used by languages that have case systems. For languages without grammatical cases (like English), this parameter has no effect. This method is available only on .NET 6.0 and later.

DateToOrdinalWordsExtensions.ToOrdinalWords(this DateTime) Method

Converts a System.DateTime to its ordinal words representation (e.g., "1st of January, 2023").

public static string ToOrdinalWords(this System.DateTime input);

Parameters

input System.DateTime

The date to be converted to ordinal words.

Returns

System.String
A string containing the date expressed in ordinal words format, culture-specific. For English: "1st of January, 2023", "22nd of December, 2020", etc.

Example

new DateTime(2023, 1, 1).ToOrdinalWords() => "1st of January, 2023" (in en-US culture)
new DateTime(2020, 12, 22).ToOrdinalWords() => "22nd of December, 2020" (in en-US culture)

Remarks

The format and style of ordinal words depends on the current culture. Uses the configured date-to-ordinal-words converter for conversion.

DateToOrdinalWordsExtensions.ToOrdinalWords(this DateTime, GrammaticalCase) Method

Converts a System.DateTime to its ordinal words representation using the specified grammatical case.

public static string ToOrdinalWords(this System.DateTime input, Humanizer.GrammaticalCase grammaticalCase);

Parameters

input System.DateTime

The date to be converted to ordinal words.

grammaticalCase GrammaticalCase

The grammatical case to use for the output words (e.g., Nominative, Genitive, etc.). This is particularly important for languages with case systems like Russian, Polish, etc.

Returns

System.String
A string containing the date expressed in ordinal words format in the specified grammatical case.

Example

// In Russian culture:
date.ToOrdinalWords(GrammaticalCase.Nominative) => different form than
date.ToOrdinalWords(GrammaticalCase.Genitive)

Remarks

The grammatical case parameter is primarily used by languages that have case systems. For languages without grammatical cases (like English), this parameter has no effect.