Skip to content
Daily Dev Tip

This tip lives in your new tab — for free.

Install for Chrome →
NESTJS

Validate and convert date query params at the boundary with ParseDatePipe

src/reports/reports.controller.ts
typescript
@Get()
async find(
  @Query('from', new ParseDatePipe()) from: Date,
  @Query('to', new ParseDatePipe({ optional: true })) to?: Date,
) {
  return this.reports.between(from, to);
}

NestJS 11 ships `ParseDatePipe`, which validates an incoming date string and hands your handler a real `Date`. Parsing dates inside the method mixes transport concerns with business logic and scatters the same `new Date()` + `isNaN` check everywhere. A pipe enforces the shape at the edge: bad input is rejected with a 400 before your code runs, and the handler signature honestly reflects that it receives a `Date`.

nestjs11pipesvalidationdates