> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blockscout.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get block number by time stamp

> Returns the block number created closest to a provided timestamp.

Required:
- `timestamp`
- `closest`




## OpenAPI

````yaml /openapi-specs/pro-api-v11.yaml get /legacy/block/get-block-number-by-time
openapi: 3.0.0
info:
  contact:
    email: info@blockscout.com
  title: Blockscout
  version: 11.0.3
servers:
  - url: http://localhost/api
    variables: {}
security: []
tags:
  - name: blocks
  - name: transactions
  - name: addresses
  - name: internal-transactions
  - name: tokens
  - name: token-transfers
  - name: smart-contracts
  - name: config
  - name: main-page
  - name: search
  - name: stats
  - name: csv-export
  - name: account-abstraction
  - name: withdrawals
  - name: advanced-filters
  - name: arbitrum
  - name: legacy
  - name: optimism
  - name: mud
  - name: celo
  - name: scroll
  - name: zilliqa
paths:
  /legacy/block/get-block-number-by-time:
    get:
      tags:
        - legacy
      summary: Get block number by time stamp
      description: |
        Returns the block number created closest to a provided timestamp.

        Required:
        - `timestamp`
        - `closest`
      operationId: BlockScoutWeb.API.Legacy.BlockController.get_block_number_by_time
      parameters:
        - description: Unix timestamp in seconds.
          in: query
          name: timestamp
          schema:
            $ref: '#/components/schemas/IntegerString'
        - description: Whether to return the block before or after the timestamp.
          in: query
          name: closest
          schema:
            enum:
              - before
              - after
            type: string
            x-struct: null
            x-validate: null
        - description: API key for rate limiting or for sensitive endpoints
          in: query
          name: apikey
          required: false
          schema:
            type: string
            x-struct: null
            x-validate: null
        - description: Secret key for getting access to restricted resources
          in: query
          name: key
          required: false
          schema:
            type: string
            x-struct: null
            x-validate: null
      responses:
        '200':
          content:
            application/json:
              schema:
                additionalProperties: false
                properties:
                  message:
                    description: >-
                      Human-readable status string — `OK` on success, a
                      descriptive error message otherwise.
                    type: string
                    x-struct: null
                    x-validate: null
                  result:
                    allOf:
                      - $ref: '#/components/schemas/GetBlockNumberByTimeResult'
                    description: Endpoint-specific payload on success; `null` on error.
                    nullable: true
                    x-struct: null
                    x-validate: null
                  status:
                    description: '`1` = OK, `0` = error, `2` = pending.'
                    enum:
                      - '0'
                      - '1'
                      - '2'
                    type: string
                    x-struct: null
                    x-validate: null
                required:
                  - status
                  - message
                  - result
                type: object
                x-struct: null
                x-validate: null
          description: Block number
      callbacks: {}
components:
  schemas:
    IntegerString:
      nullable: false
      pattern: ^-?([1-9][0-9]*|0)$
      title: IntegerString
      type: string
      x-struct: Elixir.BlockScoutWeb.Schemas.API.V2.General.IntegerString
      x-validate: null
    GetBlockNumberByTimeResult:
      additionalProperties: false
      nullable: true
      properties:
        blockNumber:
          allOf:
            - $ref: '#/components/schemas/IntegerString'
          description: Decimal-string block number.
          x-struct: null
          x-validate: null
      required:
        - blockNumber
      title: GetBlockNumberByTimeResult
      type: object
      x-struct: Elixir.BlockScoutWeb.Schemas.API.Legacy.GetBlockNumberByTimeResult
      x-validate: null

````