# DateTime

## ToShortDateString

Converts the value of the current `DateTime?` object to its equivalent short date string representation. If value is null then returns specified `defaultValue`.

```csharp
DateTime? dateTime = null;
var result = dateTime.ToShortDateString("------"); // "------"

dateTime = new DateTime(2008, 09, 25, 11, 35, 52);
result = dateTime.ToShortDateString("------"); // "09/25/2008"
```

Same works for long DateTime representation - `ToLongDateString()`

## ToString

Converts the value of the current `DateTime?` object to its equivalent string representation using the specified format and the formatting conventions of the current culture. If value is null then returns specified `defaultValue`

```csharp
DateTime? dateTime = null;
var result = dateTime.ToString("------"); // "------"

dateTime = new DateTime(2008, 09, 25, 11, 35, 52);
result = dateTime.ToString("dd-MM-yyyy hh:mm:ss", "------"); // "25-09-2008 11:35:52"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.structr.dev/utilities/abstractions/extensions/datetime.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
