Using toString([some dateTime]) Returns Wrong Time

0
I have been trying to show a dateTime value in a message. To do this, I create a text parameter (ie {1}) that turns the dateTime value into a string. I do this with the toString() function. I then add this parameter to the message template. When I test out the message, it displays the correct dateTime...most times that I try it. Once in a while, it adds a few hours to the dateTime. For example, if the actual value is 7/18/2019 3:35 PM, it will say 7/18/2019 10:35 PM. Again, this behavior is sporadic: sometimes the date will come through the toString() function perfectly, but sometimes it is wrong. This is mildly serious. There are many cases when this would be detrimental: informing a user of a meeting time, showing an event date/time, etc. We would want it to be correct in those cases.    Is there any way I can get help with this? Perhaps it is a bug that needs fixing, or I am doing something wrong?
asked
4 answers
1

And make sure to read this: https://docs.mendix.com/refguide/date-and-time-handling#1-introduction

and this: https://docs.mendix.com/refguide/datetime-handling-faq

Regards,

Ronald

 

answered
1

It sounds like you’re mixing UTC DateTimes and local DateTimes. I think every developer will have hit this problem at some point in their career, and it is confusing the first time you see it.

If you’re seeing it add 7 hours like in your example, it could be the DateTime in Mendix is stored as UTC, but you are displaying it using a local timezone such as PDT or MST.

Have a read of the documentation on the Mendix site around DateTimes, especially the DateTime Handling FAQ.

Good luck!

answered
0

Hi!

You can use the function FormatDateTime to format your DateTime value.
It's your choice to set the user's calendar and timezone or using UTC.
Perhaps this is the problem if your time is wrong, another timezone of the user?

More information about Parse & Format Date functions: https://docs.mendix.com/refguide/parse-and-format-date-function-calls

answered
0

Use Mendix’ functions. It does a lot for you. In this case you should use FormatDateTime($YourDatevalue, "MM-dd-yyyy HH:mm:ss”)

FormatDateTime($YourDatevalue, "MM-dd-yyyy HH:mm:ss”) 

  Experiment with the FormatDateTime at https://mydemoversion8-sandbox.mxapps.io/ ->FunctionFiddler->FormatDateTime

answered