<p>Is there a way to fetch a specific argo workflow age in seconds using <code>kubectl</code> command?</p>
<p>I've a requirement for comparing the argo workflow age. If the workflow age is greater than 24 hours I need to terminate the workflow.</p>

Biru
<p>You should probably use <a href="https://github.com/argoproj/argo-workflows/blob/master/examples/timeouts-workflow.yaml" rel="nofollow noreferrer">Argo Workflow's built-in, declarative timeout feature</a>:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  activeDeadlineSeconds: 86400
</code></pre>
<p>That will fail the workflow if it takes over 24 hours. To actually delete the workflow, set a <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/cost-optimisation.md#limit-the-total-number-of-workflows-and-pods" rel="nofollow noreferrer">TTL policy</a>.</p>
<pre class="lang-yaml prettyprint-override"><code>ttlStrategy:
  secondsAfterCompletion: 60
</code></pre>
<p>The <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/cost-optimisation.md#limit-the-total-number-of-workflows-and-pods" rel="nofollow noreferrer">cost optimizations</a> docs have some other notes which will be helpful when designing your cleanup strategy.</p>
<p>I can never resist a good <code>jq</code> challenge, so here's a script-based alternative:</p>
<pre class="lang-sh prettyprint-override"><code>WORKFLOW_NAME=something

if kubectl get wf -n argo &quot;$WORKFLOW_NAME&quot; -ojson | jq --exit-status 'now - (.metadata.creationTimestamp | fromdateiso8601) &gt; (24*60*60)'; then
  kubectl delete wf -n argo &quot;$WORKFLOW_NAME&quot;
fi
</code></pre>
