> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdmetrics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/datetimeformatadherence.md).

# DatetimeFormatAdherence

This metric captures whether the synthetic data adheres to a specific datatime format.

## Data Compatibility

* **Datetime** : This metric is meant to for datetime columns that are reprsented as strings with specific datetime formatting, for example YYYY-MM-DD

*This metric ignores missing values.*

## Score

**(best) 1.0**: All values in the synthetic data respect the specified datetime format

**(worst) 0.0**: No value in the synthetic data respects the specified datetime format

## How does it work?

This metrics checks each individual value of the synthetic data column to see if it follows the datetime format that is provided. The score is the proporion of synthetic data values that match the datetime format.

Note that the datetime format can only be checked if the synthetic data has a string representation. If it is present as datetime64, then the format cannot be checked and the score is NaN.

## Usage

To manually apply this metric, access the `single_column` module and use the `compute` method.

```python
from sdmetrics.single_column import DatetimeFormatAdherence

DatetimeFormatAdherence.compute(
    real_data=real_table['purchase_date'],
    synthetic_data=synthetic_table['purchase_date'],
    datetime_format='%Y-%m-%d'
)
```

**Parameters**

* (required) `real_data`: A pandas.Series object with the column of real data
* (required) `synthetic_data`: A pandas.Series object with the column of synthetic data&#x20;
* (required) `datetime_format`: A string containing the datetime format to check against. For more information, see [Python's strftime module](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes).

## FAQs

<details>

<summary>Does this metric use real data?</summary>

If the real data is represented as a string and it does not match the provided datetime format, then the metric will issue a warning but it will continue to check the synthetic data.

The final score is only based on whether the synthetic data matches the format.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/datetimeformatadherence.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
