---
title: timestampExtract
description: >-
  Firestore pipelines timestampExtract() expression helper: pull a calendar part
  (year, month, day) out of a timestamp.
next: /firestore/pipelines/subcollection
previous: /firestore/pipelines/timestamp-diff
---
> ## Documentation Index
> Fetch the complete documentation index at: https://rnfirebase.io/llms.txt
> Use this file to discover all available pages before exploring further.

## Prerequisites

- `@react-native-firebase/app` installed and native config completed per [Getting Started](/).
- `@react-native-firebase/firestore` installed and rebuilt into the native app.
- A Firestore **Enterprise** database. See [Pipelines overview](/firestore/pipelines).
- Import expression helpers from `@react-native-firebase/firestore/pipelines`.

`timestampExtract()` reads a calendar component (such as `year`, `month`, or `day`) from a timestamp. An optional third argument is a timezone, given as a string or as an expression that evaluates to one. Firestore uses it to pick the calendar for extraction, so the value you pass must be a timezone name the Firestore backend accepts.

Valid `part` values are the `TimePart` literals: `'microsecond'`, `'millisecond'`, `'second'`, `'minute'`, `'hour'`, `'day'`, `'week'`, `'week(monday)'` through `'week(sunday)'`, `'isoweek'`, `'month'`, `'quarter'`, `'year'`, `'isoyear'`, `'dayofweek'`, and `'dayofyear'`.

# Basic example

```js
import { getFirestore } from '@react-native-firebase/firestore';
import { execute, field, timestampExtract } from '@react-native-firebase/firestore/pipelines';

const db = getFirestore('your-enterprise-database-id');

const snapshot = await execute(
  db
    .pipeline()
    .collection('events')
    .select(
      timestampExtract(field('createdAt'), 'year').as('createdYear'),
      timestampExtract('createdAt', 'month').as('createdMonth'),
      timestampExtract(field('createdAt'), 'day').as('createdDay'),
    ),
);

snapshot.results.forEach(row => {
  console.log(row.data().createdYear, row.data().createdMonth, row.data().createdDay);
});
```

# With a timezone

```js
import { getFirestore } from '@react-native-firebase/firestore';
import { execute, field, timestampExtract } from '@react-native-firebase/firestore/pipelines';

const db = getFirestore('your-enterprise-database-id');

const snapshot = await execute(
  db
    .pipeline()
    .collection('events')
    .select(
      timestampExtract(field('createdAt'), 'hour', 'America/Los_Angeles').as('localHour'),
      timestampExtract('createdAt', 'dayofweek').as('weekday'),
    ),
);

snapshot.results.forEach(row => {
  console.log(row.data().localHour, row.data().weekday);
});
```

# Related helpers

{/* prettier-ignore */}
| Helper | Use when |
| --- | --- |
| `timestampExtract` | Read year, month, day, or other calendar part |
| `timestampTruncate` | Bucket timestamps to a granularity |
| `timestampDiff` | Measure elapsed time between timestamps |
| `TimePart` | Type for part literals such as `'year'` |

# Upstream reference

See the [firebase-js-sdk `timestampExtract` declaration](https://firebase.google.com/docs/reference/js/firestore_pipelines#timestampextract) for full overload signatures and supported `TimePart` values.
