How to get first & last day of a month from current date?

Hi, I need the first & last day of a month from any given date. For better understanding, if i need to back-fill data for date 07/20/2019 i.e July 20 2019, i need the first & last day has 07/01/2019 - 07/31/2019 . FYI: I'm using GIT BASH terminal.

sample code:

export DT=$(date --date='6 days ago' +%F) -> is current date for which i have data for (i.e 2019-11-26 ).

how do i use this DT var in order to get the first & last day of any month?

I appreciate your help for this task!!!

Did you look into the helpful links at the bottom of this page under "10 More Discussions You Might Find Interesting"?

Howsoever, for your first question, try

$ date --date='07/20/2019' +"%Y-%m-01"
2019-07-01

, and for the second,

$ date -d"$(date --date='07/20/2019 +1month' +"%Y-%m-01") -1sec" +%F
2019-07-31
3 Likes

Thanks a lot, it worked!