timestampExtract

Pipeline expression helper that extracts a calendar part from a timestamp.

timestampExtract() reads a calendar component—such as year, month, or day—from a timestamp. An optional timezone shifts the calendar used for extraction.

Import from the pipelines entry point:

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

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'),
      field('createdAt').timestampExtract('day').as('createdDay'),
    ),
);

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

Related helpers

HelperUse when
timestampExtractRead year, month, day, or other calendar part
timestampTruncateBucket timestamps to a granularity
timestampDiffMeasure elapsed time between timestamps
TimePartType for part literals such as 'year'

Upstream reference

See the firebase-js-sdk timestampExtract declaration for full overload signatures and supported TimePart values.

On this page