pypyr.steps.now permalink

get current local timestamp permalink

Writes the current local date & time to context now. Local time is also known as wall time.

If you want UTC time, check out pypyr.steps.nowutc instead.

If you run this step as a simple step (with no input formatting specified in nowIn), the default datetime format is ISO8601. For example: YYYY-MM-DDTHH:MM:SS.ffffff+00:00.

You can use explicit format strings to control the datetime representation. For a full list of available formatting codes, check python date & time formatting

- pypyr.steps.now # this sets {now} to YYYY-MM-DDTHH:MM:SS.ffffff+00:00
- name: pypyr.steps.echo
  in:
    echoMe: 'timestamp in ISO8601 format: {now}'
- name: pypyr.steps.now
  comment: use a custom date format string instead of the default ISO8601
  in:
    nowIn: '%A %Y %m/%d %H:%M in timezone %Z offset %z, localized to %x'
- name: pypyr.steps.echo
  in:
    echoMe: 'custom formatting for now was set in the previous step. {now}'

All inputs support substitutions.

See a worked example for pipeline now timestamp.

multiple timestamps in same pipeline permalink

If you have a pipeline where you want to refresh the timestamp multiple times, while using the same formatting, you can save yourself some typing by using set to specify the formatting nowIn context property.

- name: pypyr.steps.set
  comment: set datetime formatting string
           this will endure for the entire pipeline.
  in:
    set:
      nowIn: '%A %Y %m/%d %H:%M in timezone %Z offset %z, localized to %x'
- pypyr.steps.now # uses nowIn formatting from step 1
- name: pypyr.steps.echo
  in:
    echoMe: 'timestamp in custom format: {now}'
- pypyr.steps.now # still uses nowIn formatting from step 1
- name: pypyr.steps.echo
  in:
    echoMe: 'Using the refreshed timestamp but still same format: {now}'

see also

last updated on .