addTime with negative values

Hello,

I’m having an issue where addTime cannot subtract negative values. Here is my code:
{{tl_update_date.toDate().addHours(serverconnect_current_user.data.current_user_query.t_delta)}}
when t_delta =< 0, I get the intended result, but when the value is negative, I get this:
0NaN-aN-aN aN:aN:aN

I’ve done some research in the forum where this was met before but somehow fixed itself. @Teodor @patrick , I’d appreciate the help. If I convert the value to timestamp, nothing is displayed at all.

Thanks!

Hi @Nathaniel
What serve model are you using?
Is this on the server side or on the clientside?
What value does tl_update_date return actually before the formatting and where it does come from?

Hi Teodor,
I’m using php and this is on the client side (I didn’t know this could be done on the server side, as you seem to imply). An example of a raw tl_update_date : 2020-11-04T08:05:51Z .

Seems to be working fine for me in my tests. I have a server action outputting these values:Screenshot_39

Then on my page i have:

{{serverconnect1.data.date.toDate().addHours(serverconnect1.data.delta)}}

and the result is:

2020-11-11 11:51:42

What is the output of the delta in your server action? Are you sure it’s a number?
Do you see any errors in the browser console?

It seems to me your delta value is a string (not a number), and that’s why this happens.

Thanks for looking into this @Teodor. Can you try setting a delta that pushes the date to the previous day, ie -12, I think that’s when I detected the issue.
Something of interest is that when I try to choose the type and make sure it’s a number, nothing happens and when I open this window it reverts to text (the field is a varchar in the db):

Please check what value is actually returned from your server action, what you set in the UI does not change the value type, just tells the data picker what data type to expect.

I tested and this error appears when the value is a string and not a number.
Just run the server action in the browser and paste a screenshot of the data returned for the delta.

2 Likes

You are correct @Teodor, I changed the field to a float type and now I get the intended behavior.
Once again, thanks for the great support!

1 Like