Search code examples
dateschemaprisma2

Add Date Type to prisma2 schema


i am trying to add an Date type to my prisma2 schema. I know there is a DateTime type but I am just needing the date. Because I haven't found anything related to Date I would add an Custom input with day, month and year and create then a Date with the time 12:00 (so I have not so much problems with timezones) or a timestamp. I hope you have some better ideas or best practices. best regards and thanks!


Solution

  • create custom date scalar type with nexus. if you're using graphql you need to create a custom scalar like this.

    const CustomTime = scalarType({
      name: 'CustomTime',
      description: 'Consider time as 12 hour time.',
      asNexusMethod: 'customTime',
      parseValue(value) {
        return moment(value, '').format('')
      }
    })