Skip to main content
added 11 characters in body
Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k

bash is not the best shell for date calculation as its date-manipulation capabilities are very limited.

With zsh:

zmodload zsh/datetime d=03012012 strftime -rs d %m%d%Y%H ${d}12 strftime %m%d%Y $((d-86400)) 

With ksh93:

d=03012012 printf "%(%m%d%Y)T\n" "${d:4}${d:0:4} yesterday" 

With bash, you'd either have to do the calculation by hand or rely on perl or some GNU or FreeBSD extensions of the date utility.

bash is not the best shell for date calculation as its date-manipulation capabilities are very limited.

With zsh:

zmodload zsh/datetime d=03012012 strftime -rs d %m%d%Y%H ${d}12 strftime %m%d%Y $((d-86400)) 

With ksh93:

d=03012012 printf "%(%m%d%Y)T\n" "${d:4}${d:0:4} yesterday" 

With bash, you'd either have to do the calculation by hand or rely on perl or some GNU extensions of the date utility.

bash is not the best shell for date calculation as its date-manipulation capabilities are very limited.

With zsh:

zmodload zsh/datetime d=03012012 strftime -rs d %m%d%Y%H ${d}12 strftime %m%d%Y $((d-86400)) 

With ksh93:

d=03012012 printf "%(%m%d%Y)T\n" "${d:4}${d:0:4} yesterday" 

With bash, you'd either have to do the calculation by hand or rely on perl or some GNU or FreeBSD extensions of the date utility.

Source Link
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k

bash is not the best shell for date calculation as its date-manipulation capabilities are very limited.

With zsh:

zmodload zsh/datetime d=03012012 strftime -rs d %m%d%Y%H ${d}12 strftime %m%d%Y $((d-86400)) 

With ksh93:

d=03012012 printf "%(%m%d%Y)T\n" "${d:4}${d:0:4} yesterday" 

With bash, you'd either have to do the calculation by hand or rely on perl or some GNU extensions of the date utility.