Sexy
Sexy12mo ago

Substring problem

I have a string representing a date and time formatted as '01/02/2024/14:00'. My current approach encounters an issue where only the numbers before the first '/' are considered when using .unique, leading to incomplete data extraction. I'm exploring alternatives, such as using substring, but I haven't found a solution yet. Ideally, incorporating this into a .filter option would be beneficial for my needs. How can I accurately split this string into its constituent parts, such as day, month, year, and time, to work with each segment individually?
No description
2 Replies
lee
lee12mo ago
to do arbitrarily complex filters you can do the filter in javascript
// define a function dateLessThan that does all the string parsing you want.
// then in your query do this
for await (const reservation of ctx.db.query("messages")) {
if (dateLessThan(reservation.arrivalDate, args.day) && dateLessThan(args.day, reservation.departureDate) && reservation.roomNumber === args.room) {
return reservation;
}
}
return null;
// define a function dateLessThan that does all the string parsing you want.
// then in your query do this
for await (const reservation of ctx.db.query("messages")) {
if (dateLessThan(reservation.arrivalDate, args.day) && dateLessThan(args.day, reservation.departureDate) && reservation.roomNumber === args.room) {
return reservation;
}
}
return null;
Sexy
SexyOP12mo ago
thank you again, LEE 🍺

Did you find this page helpful?