Helm
Kubernetes
Scripting
Date Retrieval
DevOps

How to get current date in Helm

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

In Helm templates, the current date is usually generated with the now function and then formatted for labels, annotations, or config values. The main challenge is choosing the right format and understanding that render time values change on every template run. Good charts keep date handling explicit and deterministic when rollout behavior matters.

Basic Date Retrieval with now

Helm uses Go template functions plus Sprig helpers. now returns the current timestamp at render time.

yaml
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: app-build-info
5  annotations:
6    rendered-at: "{{ now }}"

This value is dynamic. Running helm template twice yields different manifests even if values.yaml is unchanged.

Formatting Dates with date

Raw timestamps are not always convenient for logs or downstream parsers. Format output with date.

yaml
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: app-build-info
5  annotations:
6    rendered-date: "{{ now | date \"2006-01-02\" }}"
7    rendered-rfc3339: "{{ now | date \"2006-01-02T15:04:05Z07:00\" }}"

Go layout syntax is based on a fixed reference date instead of symbolic tokens. Reusing tested layout strings prevents subtle mistakes.

Time Zone Aware Rendering

If templates run in different environments, timezone drift can create confusing metadata. Use dateInZone when a specific zone is required.

yaml
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: app-build-info
5  annotations:
6    rendered-utc: "{{ now | dateInZone \"2006-01-02T15:04:05Z\" \"UTC\" }}"
7    rendered-toronto: "{{ now | dateInZone \"2006-01-02 15:04:05\" \"America/Toronto\" }}"

Pinning to UTC is usually best for distributed systems and audit trails.

Prefer Deterministic Values for Releases

Dynamic timestamps inside pod template annotations can cause unnecessary rolling updates. For release metadata, prefer CI supplied values and only fall back to now when needed.

yaml
# values.yaml
build:
  timestamp: ""
yaml
1apiVersion: v1
2kind: ConfigMap
3metadata:
4  name: app-build-info
5  annotations:
6    build-timestamp: "{{ default (now | date \"2006-01-02T15:04:05Z\") .Values.build.timestamp }}"

Then in CI:

bash
helm upgrade --install demo ./chart --set build.timestamp=2026-03-04T15:30:00Z

This keeps output reproducible across repeated deployments.

Reusable Helper Template

Put common formatting in helpers to avoid repeating strings.

yaml
{{- define "mychart.renderedAtUtc" -}}
{{- now | dateInZone "2006-01-02T15:04:05Z" "UTC" -}}
{{- end -}}

Use helper output in manifests:

yaml
metadata:
  annotations:
    rendered-at: "{{ include \"mychart.renderedAtUtc\" . }}"

Centralizing this logic makes future format changes safe and fast.

Date Values in Labels Versus Annotations

Kubernetes labels have stricter character rules and length limits. If you need full RFC timestamps, annotations are safer. Use compact date strings for labels.

yaml
1metadata:
2  labels:
3    build-date: "{{ now | date \"20060102\" }}"
4  annotations:
5    build-time: "{{ now | dateInZone \"2006-01-02T15:04:05Z\" \"UTC\" }}"

This pattern avoids invalid label values while preserving detailed metadata.

Testing Template Output

Validate date fields before release.

bash
helm template demo ./chart --set build.timestamp=2026-03-04T15:30:00Z
helm lint ./chart

If deterministic output is required, run template generation twice with the same explicit timestamp and compare output. Any difference means hidden dynamic data remains.

Render Time Versus Release Time

Helm evaluates now during template rendering on the client side, not when the manifest is applied by the cluster. Document this behavior for your team so timestamp differences across operator machines do not create confusion during incident reviews.

Common Pitfalls

  • Using now in fields that control rollout checksums when deterministic behavior is required.
  • Writing token style format strings instead of Go layout strings and getting unexpected dates.
  • Relying on local render timezone instead of explicit dateInZone values.
  • Placing full timestamp strings in labels where character constraints are tighter.
  • Duplicating date formatting logic across files instead of helper templates.

Summary

  • Use now for render time values in Helm templates.
  • Format with date or dateInZone based on readability and timezone requirements.
  • Prefer CI provided timestamps when repeatable output matters.
  • Store long timestamp details in annotations, not strict labels.
  • Validate rendered manifests with fixed test values before deployment.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.