Linux Script- Date Manipulations

前端 未结 5 665
[愿得一人]
[愿得一人] 2021-01-18 06:09

I will set one date variable(Say \'08-JUN-2011\') and I want to do some calculations based on that date namely,
1. Have to get the first day of the given day\'s month.

5条回答
  •  攒了一身酷
    2021-01-18 06:24

    Using dateutils' dround tool:

    Current month:

    $ dround today -1
    2014-02-01
    

    Previous month

    $ dround today -31
    2014-01-31
    

    Last day of current month:

    $ dround today +31
    2014-02-28
    

    Of course you can use a custom date instead of today, the idea is to round down or up to the desired day-of-the month, e.g. the next first-of-the-month given 2010-10-04:

    $ dround 2010-10-04 +1d
    2010-11-01
    

提交回复
热议问题