First Day, current month:
# date -d "-0 month -$(($(date +%d)-1)) days"
First Day, last month:
# date -d "-1 month -$(($(date +%d)-1)) days"
Last Day, current month:
# date -d "-$(date +%d) days +1 month"
Last Day, last month:
# date -d "-$(date +%d) days -0 month"
Last Day, month before last month:
# date -d "-$(date +%d) days -1 month"
%d = day of month.
8 comments:
Thank you, this came in handy
Thanks man i got it
hi community,
i therefore got an issue.
i´d like to integrate this codeline in perl:
date -d "-0 month -$(($(date +%d)-1)) days"
any suggestions?
marc
Thanks dude .. it helped me a lot ... cheers for sharing !!!
Best Way Thanks A lot For Sharing
Thank you, 10 years later after the post !
Here is for next month:
Start: date -d "+1 month -$(($(date +%d)-1)) days"
End: date -d "-$(date +%d) days +2 month"
Thank you, 10 years later after the post !
Here is for next month:
Start: date -d "+1 month -$(($(date +%d)-1)) days"
End: date -d "-$(date +%d) days +2 month"
still pretty useful, thanks.
the arithmetic exception needs to be changed to work in september: $(($(date +%-d)-1))
the - after % prevents padding with 0. if not, bash tries to calculate ((09-1)) which will fail with "bash: 09: value too great for base (error token is "09")" as 09 will be interpreted as octal notation.
Post a Comment