Page 1 of 1

AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Posted: Tue May 10, 2022 8:32 am
by Bugala
Hollywoods own Time system is quite handy that you have these MakeDate() and ParseDate().

However, there is one oversight still. For example right Now I am using this Date as the tables ID:

table[date1]
table[date2]...

Difficulty is that when I want to go through this list in some sort of FOR-NEXT kind of loop, it is difficult to find out the next date.

It is easy if it happens to be like:
01-01-2001, since in that case it is simply day=day+1.

But what if date is 30, and I do +1, now I have to figure out which month it is to see if month should change or not, or even worse, if day is 28 and it is February, then I have to even figure out what year it is.

It is not anything that would be undoable, but it would be handy if there would be some command already in Hollywood where I could do something like:

Code: Select all

NewDate = AddTimeToDate(date1, #DAY, 45)
And this way 45 days would be added to the date1, and its result would be returned.

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Posted: Thu May 12, 2022 11:42 am
by Flinx
Hi Bugala,

You can do this with the timestamp functions. In my example I have used your desired syntax, otherwise the function would have been shorter.

Code: Select all

Const #DAY=1

Function p_AddTimeToDate(d$,size,offset)
	Local stamp=DateToTimestamp(d$)

	Switch size
	Case #DAY
		offset=offset*3600*24
	EndSwitch

	Return(TimestampToDate(stamp+offset, True))
EndFunction

date1="10-Dec-2021 12:00:00"
NewDate = p_AddTimeToDate(date1, #DAY, 45)
DebugPrint(NewDate)

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Posted: Thu May 12, 2022 11:48 am
by Flinx
Short version:

Code: Select all

d$="10-Dec-2021 12:00:00"
DebugPrint(TimestampToDate(DateToTimestamp(d$)+45*86400, True))

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Posted: Thu May 12, 2022 12:18 pm
by Bugala
Ah, thanks. Had missed that TimeStamp thing completely. That is handy.

Re: AddTimeToDate(date, #TIMEUNIT, amount) to Hollywood Time-commands

Posted: Thu May 12, 2022 6:12 pm
by Flinx
To make it perfect we still have to correct the UTC difference:

Code: Select all

d$="10-Dec-2021 12:00:00"
DebugPrint(TimestampToDate(DateToTimestamp(UTCToDate(d$))+42*86400, True))