I need to store in MongoDB just the time. The user types just the time, e.g. "05:20" as a string, and I need to convert and store this time.
Any tips?
I've been trying to use Date object, but with no success.
Basically you have two options:
Save time in type: String
Save date time in type: Date
But in second option you have to create Date object and set hours and minutes:
const userInput = '05:20';
const hours = userInput.slice(0, 2);
const minutes = userInput.slice(3);
const date = new Date(dateString);
date.setHours(hours, minutes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With