Linux Script- Date Manipulations

前端 未结 5 667
[愿得一人]
[愿得一人] 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:33

    As you're using Linux, hhopefully you have the GNU date utility available. It can handle almost any description of a relative date that you think of.

    Here are some examples

    date --date="last month" +%Y-%m-%d
    date --date="yesterday" +%Y-%m-%d
    date --date="last month" +%b
    x=$(date --date "10 days ago" +%Y/%m/%d)
    

    To learn more about it see GNU Date examples

    Once you use it some, you can shortcut your information gathering with date --help, which shows all the basic options (but is sometimes is hard to interpret.)

    I hope this helps.

提交回复
热议问题