<p>I don't know a way to get this directly through the RPC without looking at multiple blocks and comparing them, but the math formula is easy:</p>

<pre><code>floor(current_number_of_blocks / 2016) * 2016 - 1
</code></pre>

<p>The floor function rounds a number down to an integer value; it's available in most programming languages, although it's sometimes named something to do with integers (e.g. <code>int()</code>).  The number 2,016 is the number of blocks in a retarget period (the time between difficulty changes).</p>

<p>Here's an example command:</p>

<pre><code>bitcoin-cli getblockchaininfo | jq '.blocks / 2016 | floor * 2016 - 1'
524159
</code></pre>

<p>As requested, as of this writing, block 524,159 is the last block before the difficulty change.  To get the first block with the new difficulty, remove the <code>-1</code> (so block 524,160 in this example).</p>

<p>The command used in the above example is <a href="https://stedolan.github.io/jq/" rel="nofollow noreferrer">jq</a>.</p>

CC BY-SA 4.0
2018-05-24T19:51:51.810Z
Alternatively, `blocks - (blocks % 2016) - 1`.
Nate Eldredge
CC BY-SA 4.0
2018-05-24T15:31:39.443Z
2018-05-24T15:31:39.443Z
David A. Harding
<p>I guess if we start doing mathematical calculation then we can easily find exjact block no which was formed just before difficulty was adjusted. But is there anyway around like by using RPC by which we can find it out?</p>

<bitcoin-core><difficulty><difficulty-retargetting>
Is there any way by which we can see when was last time or which was the block that was created just before bitcoin adjusted its latest difficulty?
Parishilan Rayamajhi
# Is there any way by which we can see when was last time or which was the block that was created just before bitcoin adjusted its latest difficulty?

(Asked by: username_0 on 2018-05-24)

I guess if we start doing mathematical calculation then we can easily find exjact block no which was formed just before difficulty was adjusted. But is there anyway around like by using RPC by which we can find it out?

**Tags:** bitcoin-core, difficulty, difficulty-retargetting


---

## 1 answers

### Answer by username_1 on 2018-05-24. Score: 2

I don't know a way to get this directly through the RPC without looking at multiple blocks and comparing them, but the math formula is easy:

```
floor(current_number_of_blocks / 2016) * 2016 - 1

```

The floor function rounds a number down to an integer value; it's available in most programming languages, although it's sometimes named something to do with integers (e.g. `int()`). The number 2,016 is the number of blocks in a retarget period (the time between difficulty changes).

Here's an example command:

```
bitcoin-cli getblockchaininfo | jq '.blocks / 2016 | floor * 2016 - 1'
524159

```

As requested, as of this writing, block 524,159 is the last block before the difficulty change. To get the first block with the new difficulty, remove the `-1` (so block 524,160 in this example).

The command used in the above example is [jq](https://stedolan.github.io/jq/).

> **Comments:**
> **username_2**: Alternatively, `blocks - (blocks % 2016) - 1`.  

---

