Click here to Skip to main content
15,742,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to compare today's date in Epoch time to another Epoch date stored in a variable.

I can store today's epoch in a variable with no problem. I run into trouble when I try to store a derived $cert_experation_epoch.

This is most likely a simple issue of redirection but I'm a bit stuck.

What I have tried:

Sat Oct 16 11:42:42 PDT 2021
todays_epoch=`date "+%s"`
echo $todays_epoch

echo $cert_expiration
Oct 4 2022
cert_expiration_epoch=`date "+%s" <<< $cert_expiration`

echo $cert_expiration_epoch
1634408601  < ------ This is wrong and it looks like it's just doing the date command without redirecting the output into the variable cert_expiration_epoch.
Updated 16-Oct-21 11:42am

1 solution

cert_expiration_epoch=$(date +%s -d "$cert_expiration")

You really should start using the basic tools available.
date --help
man date
man bash

Also as someone else already told you, it's much better to use $(command) rather than `command`
Share this answer
wifinut 16-Oct-21 20:51pm    
Understood. Thanks so much!! 👍

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900