<p>You can check the genesis file for timestamp network started on (mainnet/testnet started on Byron) and use epoch/Slot for Byron (where an epoch consisted of 21600 slots, 1 slot being 20s) and shelley (where epoch consists of 432000 slots, 1 slot being 1s) respectively - all of this is in genesis JSONs you refer your node to on startup. The important bit here is knowing when Byron transited to Shelley, for mainnet, the epoch was 208.</p>
<p>You can find sample of how gLiveView calculates it <a href="https://github.com/cardano-community/guild-operators/blob/alpha/scripts/cnode-helper-scripts/env#L580-L645" rel="nofollow noreferrer">here</a>. You can also use ogmios to fetch era info from node (or use dbsync to know which epoch did forks get applied in).</p>

CC BY-SA 4.0
2022-07-31T14:15:00.410Z
2022-07-31T14:15:00.410Z
RdLrT
<p>Unfortunately while there may be such a formula it would be rather complex and would be different for each network (eg mainnet, testnet etc).</p>

CC BY-SA 4.0
2022-07-31T20:49:27.593Z
2022-07-31T20:49:27.593Z
Erik de Castro Lopo
<p>For all of the Byron Era, one slot has been 20 seconds long. Since the Shelley Hardfork (Epoch 208), one slot has been 1 second long. <strong>Assuming 1 slot will continue to be 1 second long</strong>, we can derive an approximate formula using the <a href="https://en.wikipedia.org/wiki/Unix_time" rel="nofollow noreferrer">Unix Epoch</a> time standard.</p>
<p>Epoch 208 started at 07/29/2020 at 21:44:51 PM UTC, or 1596059091 in UNIX time, at an absolute slot number of 4492800 (<a href="https://cardanoscan.io/block/4490511" rel="nofollow noreferrer">according to Cardanoscan</a>)</p>
<p>Therefore, we can approximate that the current slot is:</p>
<p>&lt;CURRENT_UNIX_TIME&gt; - 1596059091 + 4492800
or simply,</p>
<p>&lt;<a href="https://www.epochconverter.com/" rel="nofollow noreferrer">CURRENT_UNIX_TIME</a>&gt; - 1591566291</p>
<p>Which is a reasonable estimate after a quick test...</p>

CC BY-SA 4.0
2022-07-31T21:15:53.793Z
2022-07-31T21:15:53.793Z
zhekson
<p>Since cardano-cli version 8.2.0 there exists <code>cardano-cli query slot-number</code> which will calculate slot number from UTC time.</p>
<p>E.g a sample query (taken from the <a href="https://github.com/input-output-hk/cardano-node/pull/5149" rel="nofollow noreferrer">merge request</a>):</p>
<pre><code>cardano-cli -- query slot-number --mainnet --socket-path /path/to/socket '2023-04-24T09:12:42Z'
</code></pre>
<p>will give you slot 90761271.</p>

CC BY-SA 4.0
2023-07-08T20:26:27.873Z
2023-07-08T20:26:27.873Z
Cigarette Smoking Man
<p>a couple informations from the genses file are neede; particoularly you will need the POSIX timestap at which the chain was started (&quot;system start&quot;) and the slot length in milliseconds</p>
<p>The <a href="https://github.com/HarmonicLabs/plu-ts/blob/main/packages/offchain/src/toOnChain/getTxIntervalData.ts" rel="nofollow noreferrer">formula in used in plu-ts</a> is the following:</p>
<pre class="lang-typescript prettyprint-override"><code>function POSIXToSlot( POSIX: number, sysStartPOSIX: number, slotLenMs: number ): number
{
    return Math.floor( (POSIX - sysStartPOSIX) / slotLenMs );
}

function slotToPOSIX( slotN: number, sysStartPOSIX: number, slotLenMs: number ): number
{
    return sysStartPOSIX + (slotLenMs * slotN);
}
</code></pre>

CC BY-SA 4.0
2023-07-09T13:23:07.607Z
2023-07-09T13:23:07.607Z
Michele Nuzzi
<p>I need help in calculating Slot Number from Current Epoch and Slot. Is there a formula to calculate that?</p>

<cardano-cli><cardano-node>
How can I calculate slot number?
# How can I calculate slot number?

(Asked by: username_0 on 2022-07-31)

I need help in calculating Slot Number from Current Epoch and Slot. Is there a formula to calculate that?

**Tags:** cardano-cli, cardano-node

---

## 5 answers

### Answer by username_1 on 2022-07-31. Score: 1

You can check the genesis file for timestamp network started on (mainnet/testnet started on Byron) and use epoch/Slot for Byron (where an epoch consisted of 21600 slots, 1 slot being 20s) and shelley (where epoch consists of 432000 slots, 1 slot being 1s) respectively - all of this is in genesis JSONs you refer your node to on startup. The important bit here is knowing when Byron transited to Shelley, for mainnet, the epoch was 208.

You can find sample of how gLiveView calculates it [here](https://github.com/cardano-community/guild-operators/blob/alpha/scripts/cnode-helper-scripts/env#L580-L645). You can also use ogmios to fetch era info from node (or use dbsync to know which epoch did forks get applied in).


---

### Answer by username_2 on 2022-07-31. Score: 0

Unfortunately while there may be such a formula it would be rather complex and would be different for each network (eg mainnet, testnet etc).


---

### Answer by username_3 on 2022-07-31. Score: 0

For all of the Byron Era, one slot has been 20 seconds long. Since the Shelley Hardfork (Epoch 208), one slot has been 1 second long. **Assuming 1 slot will continue to be 1 second long**, we can derive an approximate formula using the [Unix Epoch](https://en.wikipedia.org/wiki/Unix_time) time standard.

Epoch 208 started at 07/29/2020 at 21:44:51 PM UTC, or 1596059091 in UNIX time, at an absolute slot number of 4492800 ([according to Cardanoscan](https://cardanoscan.io/block/4490511))

Therefore, we can approximate that the current slot is:

- 1596059091 + 4492800
or simply,

<[CURRENT\_UNIX\_TIME](https://www.epochconverter.com/)> - 1591566291

Which is a reasonable estimate after a quick test...


---

### Answer by username_4 on 2023-07-08. Score: 0

Since cardano-cli version 8.2.0 there exists cardano-cli query slot-number which will calculate slot number from UTC time.
E.g a sample query (taken from the merge request):
cardano-cli -- query slot-number --mainnet --socket-path /path/to/socket '2023-04-24T09:12:42Z'

will give you slot 90761271.


---

### Answer by username_5 on 2023-07-09. Score: 0

a couple informations from the genses file are neede; particoularly you will need the POSIX timestap at which the chain was started ("system start") and the slot length in milliseconds
The formula in used in plu-ts is the following:
function POSIXToSlot( POSIX: number, sysStartPOSIX: number, slotLenMs: number ): number
{
    return Math.floor( (POSIX - sysStartPOSIX) / slotLenMs );
}

function slotToPOSIX( slotN: number, sysStartPOSIX: number, slotLenMs: number ): number
{
    return sysStartPOSIX + (slotLenMs * slotN);
}


---

