code: def _find_or_check_datetime_variables(
      X: pd.DataFrame, variables: Variables = None
  ) -> List[Union[str, int]]:
      """
      Checks that variables provided by the user are of type datetime.
      If None, finds all datetime variables in the DataFrame.
  
      Parameters
      ----------
      X : pandas DataFrame
      variables : variable or list of variables. Defaults to None.
  
      Returns
      -------
      variables : List of datetime variables.
      """
  
      if variables is None:
          variables = [
              column
              for column in X.select_dtypes(exclude="number").columns
              if is_datetime(X[column])
              or _is_categorical_and_is_datetime(X[column])
          ]
  
          if len(variables) == 0:
              raise ValueError(
                  "No datetime variables found in this dataframe."
              )
  
      elif isinstance(variables, (str, int)):
          if is_datetime(X[variables]) or (
              not is_numeric(X[variables])
              and _is_categorical_and_is_datetime(X[variables])
          ):
              variables = [variables]
          else:
              raise TypeError("The variable entered is not datetime.")
  
      else:
          if len(variables) == 0:
              raise ValueError(
                  "The indicated list of variables is empty."
              )
  
          # check that the variables entered by the user are datetime
          else:
              vars_non_dt = [
                  column
                  for column in X[variables].select_dtypes(
                      exclude="datetime"
                  )
                  if is_numeric(X[column])
                  or not _is_categorical_and_is_datetime(X[column])
              ]
  
              if len(vars_non_dt) > 0:
                  raise TypeError(
                      "Some of the variables are not datetime."
                  )
  
      return variables
  
file_path: feature_engine/feature_engine/_variable_handling/variable_type_selection.py
imports: from typing import List, Tuple, Union
  import pandas
  from pandas.api.types import is_categorical_dtype
  from pandas.api.types import is_datetime64_any_dtype
  from pandas.api.types import is_numeric_dtype
  from pandas.api.types import is_object_dtype
  from feature_engine._variable_handling.variable_type_checks import _is_categorical_and_is_datetime, _is_categorical_and_is_not_datetime
label_desc: Use image node_id 3 for calling a global function with example usage: _find_or_check_datetime_variables(X, variables) and returns: variables