Question: I am trying to compress a log file directory on my mac. The log directory exists.

For example /var/logs/my\_log\_dir/

I am trying to run something like:

```
$ tar –cpzf x.tar.gz /var/logs/my_log_dir

```

I also tried other variations such as compressing only one of the files in the log dir - no luck. All I get from my mac is:

```
Usage:
  List:    tar -tf <archive-filename>
  Extract: tar -xf <archive-filename>
  Create:  tar -cf <archive-filename> [filenames...]
  Help:    tar --help

```

Thoughts?

Answer: 
You can also use this simple formula for finding week of the month

```
$currentWeek = ceil((date("d",strtotime($today_date)) - date("w",strtotime($today_date)) - 1) / 7) + 1;

```

**ALGORITHM :**

**Date = '2018-08-08' => Y-m-d**

1. Find out day of the month eg. 08
2. Find out Numeric representation of the day of the week minus 1 (number of days in week) eg. (3-1)
3. Take difference and store in result
4. Subtract 1 from result
5. Divide it by 7 to result and ceil the value of result
6. Add 1 to result eg. ceil(( 08 - 3 ) - 1 ) / 7) + 1 = 2
```
// self::DAYS_IN_WEEK = 7;
function getWeeksNumberOfMonth(): int
{
    $currentDate            = new \DateTime();
    $dayNumberInMonth       = (int) $currentDate->format('j');
    $dayNumberInWeek        = (int) $currentDate->format('N');
    $dayNumberToLastSunday  = $dayNumberInMonth - $dayNumberInWeek;
    $daysCountInFirstWeek   = $dayNumberToLastSunday % self::DAYS_IN_WEEK;
    $weeksCountToLastSunday = ($dayNumberToLastSunday - $daysCountInFirstWeek) / self::DAYS_IN_WEEK;

    $weeks = [];
    array_push($weeks, $daysCountInFirstWeek);
    for ($i = 0; $i < $weeksCountToLastSunday; $i++) {
        array_push($weeks, self::DAYS_IN_WEEK);
    }
    array_push($weeks, $dayNumberInWeek);

    if (array_sum($weeks) !== $dayNumberInMonth) {
        throw new Exception('Logic is not valid');
    }

    return count($weeks);
}

```

Short variant:

```
(int) (new \DateTime())->format('W') - (int) (new \DateTime('first day of this month'))->format('W') + 1;

```