Problem

You might need to get a timestamp of yesterday in any script.

Analysis

Do not think about any scripting and converting dates. Just use the old good ‘date’ command.

Solution

This script should be self explanatory:

#!/bin/bash
set -o verbose on
date
date --date=now
date --date=today # same thing
date --date='3 seconds'
date --date='3 seconds ago'
date --date='4 hours'
date --date='tomorrow'
date --date='1 day'
date --date='1 days'
date --date='yesterday'
date --date='1 day ago'
date --date='1 days ago'
date --date='1 week'
date --date='1 fortnight'
date --date='1 month'
date --date='1 year'
Timestamp of yesterday using ‘date’ command
Tagged on:

Leave a Reply