Monday, February 21, 2022

[SOLVED] Linux Date Function forward/backward time

Issue

Is there an option of date function?

How do I get LOAD_TEST_START to be 2 minutes forward?

How do I get LOAD_TEST_END to be 2 minutes back?

LOAD_TEST_START=$(date -u +%FT%TZ)
LOAD_TEST_END=$(date -u +%FT%TZ)

Solution

This answer helped me and works on the linux-version of date.

LOAD_TEST_START=$(date +%FT%TZ -d "2 minutes ago")
LOAD_TEST_END=$(date +%FT%TZ -d "2 minutes")

On macos/FreeBSD one can use

LOAD_TEST_START=$(date -v+2M +%FT%TZ)
LOAD_TEST_END=$(date -v-2M +%FT%TZ)


Answered By - kometen
Answer Checked By - David Marino (WPSolving Volunteer)