Raw data of dates in all blocks using PHP or R Is it possible to obtain the date (time stamp) of each bitcoin block so far, using languages like PHP or R?. 

I am developing an analysis of the time series of bitcoin use for a scientific project, and while many sources provide averages, few provide the raw data. 

In I related post (Raw data of transactions in all blocks), a person (amaclin) kindly provided the number of transactions in all existing blocks, could it be possible to obtain the date?.

Is this something that can be done in R or PHP?
I've written this simple PHP code with an explanation for each comma

PHP code

&lt;?php

$lastBlockEnd = $this-&gt;MyRPC-&gt;BitcoinCoreCommand('getblockcount' , []);
// https://bitcoin.org/en/developer-reference#getblockcount

for ($i = 0; $i &lt;= $lastBlockEnd; $i++){
    $blockHash = $this-&gt;MyRPC-&gt;BitcoinCoreCommand('getblockhash' , [$i]);
    //https://bitcoin.org/en/developer-reference#getblockhash
    $blockData = $this-&gt;MyRPC-&gt;BitcoinCoreCommand('getdata' , [$blockHash]);
    //https://bitcoin.org/en/developer-reference#getblock
    $block[$i]['time'] = $blockData['time'];
    $block[$i]['hash'] = $blockHash;
}

print_r($block);


Code Explanation


We are getting total available blocks number, say its 65443
we will start looping from block number 0 to 65443



  Note: You should send "batch request" instead of calling each block separately 
  - we are getting block hash, then we're calling getdata and passing that block hash.


Now we've got the following response:

{
    "hash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
    "confirmations": 447014,
    "strippedsize": 215,
    "size": 215,
    "weight": 860,
    "height": 1,
    "version": 1,
    "versionHex": "00000001",
    "merkleroot": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
    "tx": [
        "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
    ],
    "time": 1231469665,
    "mediantime": 1231469665,
    "nonce": 2573394689,
    "bits": "1d00ffff",
    "difficulty": 1,
    "chainwork": "0000000000000000000000000000000000000000000000000000000200020002",
    "previousblockhash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
    "nextblockhash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd"
}


Finally, We are storing time and block hash in an array and printing it.