<p>To find the height of a block with only the raw blockchain (or block header) data, you need to follow through the sequence of references all the way to the genesis block.</p>

<p>Of course, there are external services offering this information in their API.</p>

<p>As for your premise, to calculate difficulty you don't need to know how many blocks were created in two weeks, only how much time passed for 2016 blocks (or actually 2015 blocks due to an off-by-one bug).</p>

CC BY-SA 3.0
2013-09-10T16:52:05.003Z
2013-09-10T16:52:05.003Z
Meni Rosenfeld
<p>I use bitcoin Abe (MySQL DB) to parse the block chain so I can import it into Matlab for analytics. There is what appears to be a network attack around <code>block_id</code> 225503. To get around this and other orphan blocks, I started in the <code>block</code> table and queried <code>SELECT block_id,block_height,block_ntime,block_total_satoshis,prev_block_id FROM abe.block WHERE block_id=" block# "</code> I then used <code>prev_block_id</code> and started at the most recent block in the block chain and worked iteratively backwards using the <code>prev_block_id</code> to pick the next <code>block_id</code>.</p>

CC BY-SA 3.0
2014-01-14T02:37:16.617Z
2014-01-14T02:37:16.617Z
Cal Abel
<p>I want to create a difficulty calculator and need to know when each 2016th block has been created and how many blocks were created in the previous two weeks.</p>

<p>Do I have to count and label each block from the genesis block up manually or is there an easier way without having to download and parse the entire blockchain or use an external service?</p>

<blockchain><development><difficulty>
How do you determine which position a block is in the blockchain?
Dan
# How do you determine which position a block is in the blockchain?

(Asked by: username_0 on 2013-09-10)

I want to create a difficulty calculator and need to know when each 2016th block has been created and how many blocks were created in the previous two weeks.

Do I have to count and label each block from the genesis block up manually or is there an easier way without having to download and parse the entire blockchain or use an external service?

**Tags:** blockchain, development, difficulty


---

## 2 answers

### Answer by username_1 on 2013-09-10. Score: 1 | Accepted answer

To find the height of a block with only the raw blockchain (or block header) data, you need to follow through the sequence of references all the way to the genesis block.

Of course, there are external services offering this information in their API.

As for your premise, to calculate difficulty you don't need to know how many blocks were created in two weeks, only how much time passed for 2016 blocks (or actually 2015 blocks due to an off-by-one bug).


---

### Answer by username_2 on 2014-01-14. Score: 0

I use bitcoin Abe (MySQL DB) to parse the block chain so I can import it into Matlab for analytics. There is what appears to be a network attack around `block_id` 225503. To get around this and other orphan blocks, I started in the `block` table and queried `SELECT block_id,block_height,block_ntime,block_total_satoshis,prev_block_id FROM abe.block WHERE block_id=" block# "` I then used `prev_block_id` and started at the most recent block in the block chain and worked iteratively backwards using the `prev_block_id` to pick the next `block_id`.


---

