0

adding eg 7 days to a date+time field

Hi, I just cant figure out how to add days to a date+time field and I couldnt find anything in forum.

Lets say eg 15.10.2024, 9:00

date+time field := date(year(date+time), month(date+time), day(date+time) + 7);

forwards the date by 7 days to 22.10.2024, but the hour and minutes turn to 1:00.

thnx

10 replies

null
    • Fred
    • 10 hrs ago
    • Reported - view

    That is because you didn’t tell Ninox what time to add. Try:

    date+time field := date(year(date+time), month(date+time), day(date+time) + 7,time(date+time);
    

    Here is the documentation for datetime().

      • Kruna
      • 9 hrs ago
      • Reported - view

       thank you. 

      This is what I assumed and I was could find info about the hour and minute issue. I also saw the documentation, but no way for me to adapt the script.

      I tried your script and there is an error message. First I thought that at the end a bracket is missing, but still there is an error.

      • John_Halls
      • 8 hrs ago
      • Reported - view

       Try

      datetime(year('Date + Time'), month('Date + Time'), day('Date + Time') + 7) + time('Date + Time')
      
      
      • Fred
      • 8 hrs ago
      • Reported - view

      Silly me. I didn't follow the docs myself. 😄 You can only use numbers in datetime().

      So you have to do a bit of math to get the hour and minutes into a human readable form.

      Try:

      let h := floor(number(time(Terminbeginn)) / 3600000);
      let m := (number(time(Terminbeginn)) - 3600000 * h) / 60000;
      Terminbeginn := datetime(year(Terminbeginn),month(Terminbeginn),day(Terminbeginn)+7,h,m)
      

      The math behind lines 1 and 2 is that there are 3,600,000 milliseconds in an hour and 60,000 milliseconds in a minute. So h finds the number of hours then m subtracts the total number of milliseconds hours then divides by 60,000 to find the number of minutes in Terminbeginn.

      • Fred
      • 8 hrs ago
      • Reported - view

      I get an function not defined error message of number, number, string.

      • John_Halls
      • 8 hrs ago
      • Reported - view

       Hi Fred, worked for me. datetime(number, number, number) gives the date plus 00:00:00, and then I just added the time element to this.

      • Fred
      • 8 hrs ago
      • Reported - view

      Of course, I put my parenthesis in the wrong place. I was trying to do something like this. Thanks for the simpler way.

    • Kruna
    • 8 hrs ago
    • Reported - view

     , thank you so much guys!👍Both versions work perfectly. 

    Now I have the problem, which one should I take?🤔😂

    thnx again

      • Fred
      • 8 hrs ago
      • Reported - view

      use

      • Fred
      • 3 hrs ago
      • Reported - view

      Please mark the post answered.

Content aside

  • 3 hrs agoLast active
  • 10Replies
  • 34Views
  • 3 Following