<p>It is impossible to know that actual timespan due to network delays, malicious miner behavior, being offline, etc. The target readjustment just uses the closest thing it can get to the actual timespan which is the difference in the timestamps. However those timestamps can be faked as well, so it is just an estimate.</p>

CC BY-SA 4.0
2018-09-12T04:16:32.787Z
You are right. but I just want to make sure that timestamp is also very inaccurate.
not only because of network delays, malicious behavior, offline, but also because of choosing rules of timestamp
Hyun Seok Jeong
CC BY-SA 4.0
2019-09-01T16:13:10.657Z
Yes, the network rules permit blocks to be created with timestamps up to two hours in the future, and generally up to one hour in the past (it has to be after the median of the timestamps of the 11 past blocks).
Pieter Wuille
CC BY-SA 4.0
2018-09-12T02:51:03.327Z
2018-09-12T02:51:03.327Z
Ava Chow
<p>I know how to calculate difficulty, and I know it is increased or decreased by checking the timespan of the past 2016 blocks. </p>

<p>and I found actual code for calculating timespan: <a href="https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp#L55" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp#L55</a></p>

<pre><code>actual_timespan = last_block-&gt;get_timestamp() - first_block-&gt;get_timestamp()
</code></pre>

<p>But, as I know timestamp in block is not the exact time of the mining:
<a href="https://en.bitcoin.it/wiki/Block_timestamp" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Block_timestamp</a></p>

<p>So, the timespan which is used to calculate the next difficulty is not the exact timespan but approximate value. Am I right? </p>

<difficulty><timestamp>
When update mining difficulty, Is the timespan of the past 2016 blocks approximated value?
Hyun Seok Jeong
# When update mining difficulty, Is the timespan of the past 2016 blocks approximated value?

(Asked by: username_0 on 2018-09-12)

I know how to calculate difficulty, and I know it is increased or decreased by checking the timespan of the past 2016 blocks.

and I found actual code for calculating timespan: <https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp#L55>

```
actual_timespan = last_block->get_timestamp() - first_block->get_timestamp()

```

But, as I know timestamp in block is not the exact time of the mining:
<https://en.bitcoin.it/wiki/Block_timestamp>

So, the timespan which is used to calculate the next difficulty is not the exact timespan but approximate value. Am I right?

**Tags:** difficulty, timestamp


---

## 1 answers

### Answer by username_1 on 2018-09-12. Score: 1

It is impossible to know that actual timespan due to network delays, malicious miner behavior, being offline, etc. The target readjustment just uses the closest thing it can get to the actual timespan which is the difference in the timestamps. However those timestamps can be faked as well, so it is just an estimate.

> **Comments:**
> **username_0**: You are right. but I just want to make sure that timestamp is also very inaccurate. not only because of network delays, malicious behavior, offline, but also because of choosing rules of timestamp  
> **username_2**: Yes, the network rules permit blocks to be created with timestamps up to two hours in the future, and generally up to one hour in the past (it has to be after the median of the timestamps of the 11 past blocks).  

---

