Change month and year in a time script - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Change month and year in a time script (/showthread.php?tid=2179) |
Change month and year in a time script - Carlos Padilla - 03.08.2019 Good companions, thanks for reading this thread. This is to tell you that I have one function per event which calls a user library. The idea is that by means of a button you can complete the fields of a date and a time variable based on previously established parameters, so that if it was set to "dia_tiem1" in 1 and "hor_tiem1" in 13 : 00: 00, automatically the value of 13:00:00 will be written in the "hour_checkout" variable and in the "day_checkout" variable the day following the current date will be written. The problem occurs is when the end of the month arrives, the ideal is that when executing the button on day 31 in the variable "dia_checkout" change the month and becomes September 1 for example, but it happens that it does not exceed 31 And neither does the month change. I imagine that this same problem I will have when it is December 31, the ideal would be that in the variable "dia_checkout" becomes January 1 of the following year, but this will not happen. I abbreviate the code that works for me as long as it is not 31 of the month and of which I have doubts about its behavior on the 30th and in February which has 28 days and 29 when it is leap. Thank you and I am attentive to your comments. Code: function perfil_fecha(obj_perf,hora_checkout,dia_checkout,dia_tiem1,hor_tiem1,dia_tiem2,hor_tiem2,dia_tiem3,hor_tiem3) RE: Change month and year in a time script - admin - 05.08.2019 You can use this function: Code: function shiftdate(date, days) First argument is date table (with day/month/year data), second argument is number of days to add. This will handle month/year rollover correctly. RE: Change month and year in a time script - Carlos Padilla - 05.08.2019 Hi Admin, thanks for replying. I used the function, but it is not working for me, I don't know if it is because of my bad configuration of both the types of data or I am omitting something previous. I attach the error message, the object settings and the script by event. Thank you and I am attentive to your comments. Script by event Code: require('user.perfil_horario') Code: function shiftdate(date,days) Log Error: Event for Tiempo Check Out (32/0/24) 05.08.2019 10:55:21 User library perfil_horario:2: attempt to index local 'date' (a string value) stack traceback: User library perfil_horario:2: in function 'shiftdate' User script:15: in main chunk RE: Change month and year in a time script - Daniel - 05.08.2019 Hi You have error in line 3, and you should split our result from the function to some variable. Code: function shiftdate(date,days) RE: Change month and year in a time script - Carlos Padilla - 08.08.2019 Hi Admin and Daniel, thanks for replying. With your help I could already do the Script. Thank you |