NewTime_s = DateTime2ELTime_s(ELTimeToDateTime_s(Time_s) - 60);
It was not changing the NewTime_s at all. I deleted that prior post and replaced it with this one when I remembered the function I wrote below back in January. It has the proper use of the above command set. This function is a lot easier to remember and it is worth studying since it takes a while to figure out how the above command is to be used properly (at least it took me a while).
I just checked. It turns out the study I have that was using the above command instead of the function below is properly using the "OneMinute" value of OneMinute(1/1440), {1 divided by the number of minutes in a day}. That is the problem with the above command. It is too complex to remember for occasional use every 1 or 2 years. The function immediately below spells it out for you (for documentation purposes at least). Otherwise you can just extract what you need from the function below.
Code: Select all
{A_TimeAddSub_s - Written by John Bowles}
{
Sample Calls
Result_s = A_TimeAddSub_s(Time_s, "A", 1, "S"); {Time_s add 1 second}
Result_s = A_TimeAddSub_s(Time_s, "A", 5, "M"); {Time_s add 5 minutes}
Result_s = A_TimeAddSub_s(Time_s, "A", 3, "H"); {Time_s add 3 hours}
Result_s = A_TimeAddSub_s(Time_s, "S", 3, "S"); {Time_s subtract 3 seconds}
Result_s = A_TimeAddSub_s(Time_s, "S", 3, "M"); {Time_s subtract 3 minutes}
Result_s = A_TimeAddSub_s(Time_s, "S", 2, "H"); {Time_s subtract 2 hours}
}
{
This is a test caller you can use to learn to trust it. Just copy the actual code out to a study, compile it and test it on a seconds chart.
inputs: Units(3);
Print( File("C:\A_DateTimeLearningTests1.txt"),
" Time_s", " " ,
Time_s, " --- " ,
" add ", NumToStr(units,0), " Sec", " " ,
A_TimeAddSub_s(Time_s,"A", units, "S") , " -" ,
" add ", NumToStr(units,0), " min", " " ,
A_TimeAddSub_s(Time_s,"A", units, "M") , " -" ,
" add ", NumToStr(units,0), " hour", " " ,
A_TimeAddSub_s(Time_s,"A", units, "H") , " -" ,
" sub ", NumToStr(units,0), " Sec", " " ,
A_TimeAddSub_s(Time_s,"S", units, "S") , " -" ,
" sub ", NumToStr(units,0), " min", " " ,
A_TimeAddSub_s(Time_s,"S", units, "M") , " -" ,
" sub ", NumToStr(units,0), " hour", " " ,
A_TimeAddSub_s(Time_s,"S", units, "H") , " " ,
" ");
}
inputs:
TimeIn(NumericSimple),
AddSub(StringSimple),
UnitsIn(NumericSimple),
UnitsToAdd(StringSimple);
variables:
AddSubAmt(0),
OneHour(1/24), {1 divided by the number of hours in a day}
OneMinute(1/1440), {1 divided by the number of minutes in a day}
OneSecond(1/86400); {1 divided by the number of seconds in a day}
if AddSub = "A" then
AddSubAmt = 1;
if AddSub = "S" then
AddSubAmt = -1;
if AddSubAmt = 0 then
A_TimeAddSub_s = 0
else
begin
if UnitsToAdd = "S" then
A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneSecond) * AddSubAmt));
if UnitsToAdd = "M" then
A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneMinute) * AddSubAmt));
if UnitsToAdd = "H" then
A_TimeAddSub_s = DateTime2ELTime_s(ELTimeToDateTime_s(TimeIn) + ((UnitsIn * OneHour) * AddSubAmt));
end;