Next.js Discord

Discord Forum

prisma datetime type not assignable to string

Answered
Black-whiskered Vireo posted this in #help-forum
Open in Discord
Avatar
Black-whiskered VireoOP
I have a prisma object which has a coloumn of type DateTime.
in the prop here you see I have given it type Date because of that..
how can I fix this error now
Image
Answered by chisto
try making it string
{String(time)}
or time.toLocaleDateString()
or toLocaleTimeString()
View full answer

9 Replies

Avatar
Black-whiskered VireoOP
Image
Image
Avatar
try making it string
{String(time)}
or time.toLocaleDateString()
or toLocaleTimeString()
Answer
Avatar
Black-whiskered VireoOP
nice thanks done
Avatar
British Shorthair
Or use momentjs or datejs to actually format the date for displaying. These libraries can handle both as input: string or date
Avatar
Black-whiskered VireoOP
does this convert the data to string on the client side or server side?
all of this code runs on the server side right? so how to format the date to the users preference instead of the servers
Avatar
British Shorthair
The code runs wherever your component runs.
If you want to make sure to suit it to your users preferences, you either take the accept language header (on the server) or the browser locale (on the client). Alternatively you allow storing a preference in the user profile.