Description
Currently in Mendix, there is no straightforward way to take an existing DateTime object and swap out only its date or only its time component while preserving the other. To do this today, you have to manually extract individual parts (year, month, day, hours, minutes, seconds) using functions like dateTimeToString or the various getYear/getHours-style expressions, and then reconstruct a new DateTime using dateTime(year, month, day, hour, minute, second). This is unnecessarily verbose and error-prone for what should be a trivial operation.
The proposed solution
Introduce two new microflow expression functions:
replaceDate(originalDateTime, newDate) — takes an existing DateTime and a new date value, and returns a new DateTime that keeps the original time but uses the date from the second argument.replaceTime(originalDateTime, newTime) — takes an existing DateTime and a new time value (or explicit hour/minute/second parameters), and returns a new DateTime that keeps the original date but applies the new time.Optionally, a more flexible combined version could look like:
changeDateTime(originalDateTime, year, month, day, hour, minute, second) where any parameter can be empty/null to mean "keep the existing value."
Why this matters:
This pattern comes up constantly in real-world applications — scheduling systems where a user picks a new time slot for an existing appointment, deadline calculators that shift only the date, time-zone-aware adjustments, and many more. Right now every developer solves this the same verbose way, which means it's clearly a missing built-in. Formalizing it reduces bugs, improves readability of microflow expressions, and aligns Mendix with what most modern date/time libraries already offer natively (e.g. Java's LocalDateTime.withHour(), JavaScript's date-fns setHours(), Python's datetime.replace()).