Quote:
Originally Posted by xowl
Hi, I found a faster way to do this.
I post them here cause it shows how powerful date is:
FirstDay
date -d "-1 month -$(($(date +%d)-1)) days"
Lastday
date -d "-$(date +%d) days -1 month"
|
Thanks xowl for such interesting answer . There is a correction here for LastDay of previous month:
OUTPUT for
date -d "-$(date +%d) days -1 month"(Lastday) will be the last day of previous to previous month.
So,
FirstDay previous month:
date -d "-1 month -$(($(date +%d)-1)) days"
Lastday previous month:
date -d "-$(date +%d) days"
FirstDay current month:
date -d "-$(($(date +%d)-1)) days"
Lastday current month:
date -d "-$(date +%d) days +1 month"