> This page location: Math Functions > DIV
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL DIV() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `DIV()` function to perform integer division.

## Introduction to the PostgreSQL DIV() function

The `DIV()` function is a useful tool for performing integer division. Unlike the division operator (`/`), which returns a floating-point result, the `DIV()` function provides an integer quotient.

Here's the basic syntax of the `DIV()` function:

```sql
DIV(dividend, divisor)
```

In this syntax:

- `dividend` is the number that you want to divide.
- `divisor` is the number to which to divide the dividend.

The `DIV()` function returns the integer quotient of the division.

## PostgreSQL DIV() function examples

Let's explore some examples of using the `DIV()` function.

### 1) Basic DIV() function example

The following uses the `DIV()` function to return the result of dividing 10 by 3:

```sql
SELECT DIV(10,3) as result;
```

Output:

```text
 result
--------
      3
(1 row)
```

The result is 3.

Unlike regular division, the `DIV()` function truncates any fractional part of the result and returns only the integer part.

### 2) Grouping data into bins

You can group numerical data data into bins using the `DIV()` function. For example, you can group film from the `film` table of the [sample database](../postgresql-getting-started/postgresql-sample-database) into bins of 30 minutes:

```sql
SELECT
  title,
  DIV(length, 30) * 30 as bin
FROM
  film
GROUP BY
  bin,
  title
ORDER BY
  title;
```

Output:

```
            title            | bin
-----------------------------+-----
 Academy Dinosaur            |  60
 Ace Goldfinger              |  30
 Adaptation Holes            |  30
 Affair Prejudice            |  90
 African Egg                 | 120
 Agent Truman                | 150
 Airplane Sierra             |  60
...
```

In this example, we group the lengths of films into bins of 30 minutes.

### 3) Using the PostgreSQL DIV() for calculating ages

First, [create a new table](../postgresql-tutorial/postgresql-create-table) called `employees` and [insert some data into it](../postgresql-tutorial/postgresql-insert-multiple-rows):

```sql
CREATE TABLE employees (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    birthdate DATE NOT NULL
);

INSERT INTO employees (name, birthdate)
VALUES
    ('John Doe', '1990-05-15'),
    ('Jane Smith', '1985-09-20'),
    ('Michael Johnson', '1982-03-10'),
    ('Emily Brown', '1995-11-28')
RETURNING *;
```

Output:

```text
 id |      name       | birthdate
----+-----------------+------------
  1 | John Doe        | 1990-05-15
  2 | Jane Smith      | 1985-09-20
  3 | Michael Johnson | 1982-03-10
  4 | Emily Brown     | 1995-11-28
(4 rows)
```

Second, calculate the age of each employee:

```sql
SELECT name, DIV(EXTRACT(YEAR FROM AGE(current_date, birthdate)), 1) AS age
FROM employees;
```

Output:

```
      name       | age
-----------------+-----
 John Doe        |  33
 Jane Smith      |  38
 Michael Johnson |  41
 Emily Brown     |  28
(4 rows)
```

How it works.

- Use the [AGE()](../postgresql-date-functions/postgresql-age) function to calculate age.
- Use the [EXTRACT()](../postgresql-date-functions/postgresql-extract) function to extract the year from the age.
- Use the `DIV()` function to return the integer part of the age.

## Summary

- Use the PostgreSQL `DIV()` function to perform integer division.

---

## Related docs (Math Functions)

- [ABS](https://neon.com/postgresql/postgresql-math-functions/postgresql-abs)
- [CBRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-cbrt)
- [CEIL](https://neon.com/postgresql/postgresql-math-functions/postgresql-ceil)
- [DEGREES](https://neon.com/postgresql/postgresql-math-functions/postgresql-degrees)
- [EXP](https://neon.com/postgresql/postgresql-math-functions/postgresql-exp)
- [FACTORIAL](https://neon.com/postgresql/postgresql-math-functions/postgresql-factorial)
- [FLOOR](https://neon.com/postgresql/postgresql-math-functions/postgresql-floor)
- [GCD](https://neon.com/postgresql/postgresql-math-functions/postgresql-gcd)
- [LCM](https://neon.com/postgresql/postgresql-math-functions/postgresql-lcm)
- [LN](https://neon.com/postgresql/postgresql-math-functions/postgresql-ln)
- [LOG](https://neon.com/postgresql/postgresql-math-functions/postgresql-log)
- [MOD](https://neon.com/postgresql/postgresql-math-functions/postgresql-mod)
- [MIN_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-min_scale)
- [PI](https://neon.com/postgresql/postgresql-math-functions/postgresql-pi-function)
- [POWER](https://neon.com/postgresql/postgresql-math-functions/postgresql-power)
- [RADIANS](https://neon.com/postgresql/postgresql-math-functions/postgresql-radians)
- [RANDOM](https://neon.com/postgresql/postgresql-math-functions/postgresql-random)
- [ROUND](https://neon.com/postgresql/postgresql-math-functions/postgresql-round)
- [SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-scale)
- [SIGN](https://neon.com/postgresql/postgresql-math-functions/postgresql-sign)
- [SQRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-sqrt)
- [TRIM_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-trim_scale)
- [TRUNC](https://neon.com/postgresql/postgresql-math-functions/postgresql-trunc)
- [WIDTH_BUCKET](https://neon.com/postgresql/postgresql-math-functions/postgresql-width_bucket)
