0

I m trying to get yesterday date, it's not working in hp ux server.

Prev_date=$(date +"y%m%d" -d "1 day ago")

For this I m still getting current date only. 20210811

Could you please help on the same.

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • Already discussed here - https://stackoverflow.com/questions/3517982/in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable – Alif Biswas Aug 11 '21 at 09:16
  • This is unrelated to any shell, only the version of `date` you are using. – chepner Sep 07 '21 at 12:34
  • @chepner, to be precise it is not about version but the release of `date` utility. And AFAIK none of popular unises (AIX, Solaris, HP-UX) support `--date` key – Romeo Ninov Dec 05 '21 at 20:21
  • @user16598664, check the question on the link and see the solution in accepted answer. – Romeo Ninov Dec 05 '21 at 20:25
  • @RomeoNinov By "version", I don't mean a particular numbered release from any particular project. (And if you are going to pretend Unix is a 3rd-declension Latin noun, the plural would be *unices*.) – chepner Dec 05 '21 at 20:36
  • @chepner, my latin is "tabula rasa" :D . Get your point about the version – Romeo Ninov Dec 05 '21 at 20:39
  • Does this answer your question? [In a unix shell, how to get yesterday's date into a variable?](https://stackoverflow.com/questions/3517982/in-a-unix-shell-how-to-get-yesterdays-date-into-a-variable) – Romeo Ninov Dec 05 '21 at 20:51

2 Answers2

0

You missed a percentage in front of the 'y': this is working fine for me:

echo $(date +"%y%m%d" -d "1 day ago")
Dominique
  • 16,450
  • 15
  • 56
  • 112
0

You can use below command, if you want.

date --date=' 1 days ago' '+%Y-%m-%d'

It will give result like

 2021-09-06

I prefer this format since most of the time my scripts include SQL queries for data fetch and hence date is required to filter out data on daily basis.

chepner
  • 497,756
  • 71
  • 530
  • 681
vkeeWorks
  • 89
  • 7