```const users = await ctx.prisma.user.findMany({ ...
# orm-help
g
Copy code
const users = await ctx.prisma.user.findMany({
      where: {
        profile: {
          firstName: {
            contains: args.where.firstName
          },
          DOB: {
            
          }
        }
      }})
Hi All, need your help .. I am trying to build a query that returns a list of users that have a birthday today .. there is a filed in the user model that has the DOB stored .. Is there anyway to do so?
r
It would be:
Copy code
DOB: {
  gte: "2021-10-11",
  lt: "2021-10-12"
}
You would obviously want those dates to be dynamically generated
t
depending on how you store the date, you can do
DOB: new Date().setUTCHours(0, 0, 0, 0)
g
Hi Tyler, I store it with the default ISO format .. I feel like I should have stored it in a UTC format
@Ricky Hopkins what If i want to ignore the year ?
r
Oh yea, sorry I got that one wrong. Let me have a think
What db are you using?
g
Postgres
t
ahha, afaik prisma is severely lacking in the computed data department, so you will most likley need to split the DBO into three/four fields, date, day/month and year
r
You might need to write a manual query using he
DATE_PART
function in postgres. https://stackoverflow.com/questions/6758778/getting-all-entries-whose-birthday-is-today-in-postgresql
Copy code
prisma.$queryRaw`SELECT * FROM User`
m
Such dates as birthdays should be stored in native Date (not DateTime) type if possible. If that's not possible, such dates should be stored as string
"1990-04-30"
,
"19900430"
or an integer
19900430
. Because you don't want somebody's birthday to be on different days on different timezones. It might bit you someday, dealing with timezones is hard. If you're storing ISO format without time then you can use `endsWith`:
Copy code
DOB: {
    endsWith: '10-11' // you would make that string earlier using todays date
}
Further reading: https://stackoverflow.com/questions/33129478/store-date-of-birth-in-database-as-unix-time/33130024#33130024