title: How to check datetime format in IF statement python
body: <p>Say I have two types of datetime format need to check which are the following:</p>
  <ol>
  <li><code>%Y-%m-%dT%H:%M:%S.%f%z</code></li>
  <li><code>%Y-%m-%d</code></li>
  </ol>
  <p>and convert them to this format <code>%Y-%m-%d %H:%M:%S UTC</code>.</p>
  <p>My code at the moment only manage to check one condition :</p>
  <pre><code>if val is None:
    val2 = val
  else:
    val2 = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S.%f%z').__format__(&quot;%Y-%m-%d %H:%M:%S UTC&quot;)
  </code></pre>
  <p>My pseudocode will be :</p>
  <pre><code>if val is None:
     val2 = val
  elif val is in &quot;%Y-%m-%d&quot; format:
     do this --&gt; val2 = convert from &quot;%Y-%m-%d&quot; to &quot;%Y-%m-%d %H:%M:%S UTC&quot; (eg: 2020-09-01 00:00:00 UTC)
  else:
     val2 = datetime.strptime(val, '%Y-%m-%dT%H:%M:%S.%f%z').__format__(&quot;%Y-%m-%d %H:%M:%S UTC&quot;)
  </code></pre>
  <p>The time format will be <code>00:00:00 UTC</code> constantly because there is no timestamp specified in the first place.</p>