Skip to content

Instantly share code, notes, and snippets.

@Jtosbornex
Last active December 29, 2020 18:23
Show Gist options
  • Save Jtosbornex/f2153cf8822ec5e910b729b51cafec33 to your computer and use it in GitHub Desktop.
Save Jtosbornex/f2153cf8822ec5e910b729b51cafec33 to your computer and use it in GitHub Desktop.
Typeorm Date Comparisons
import { FindOperator, LessThan, MoreThan } from "typeorm"
import moment, { Moment, MomentInput } from 'moment';
export const MoreThanDate = (date:MomentInput) => MoreThan(
new FindOperator(
'moreThan',
moment(date).format( 'YYYY-MM-DD HH:mm:ss' ),
)
);
export const LessThanDate = (date:MomentInput) => LessThan(
new FindOperator(
'lessThan',
moment(date).format( 'YYYY-MM-DD HH:mm:ss' ),
)
)
@Jtosbornex
Copy link
Author

For some reason LessThan and MoreThan don't work as expected for date values. This works great for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment