Hi:
Imagine you started a project today at 00:00:00. We'll call that Day 1. At 1 second past midnight you'd be on day 2. You could calculate this easily using the difference in seconds. But what if you started your project today at 23:59:59. In calendar days you'd be on day 2 two seconds later. That's what I need. I need to know the day of a project in CALENDAR days given today and a start date.
Put differently let's suppose you start a project on a Monday. Any time during Monday should be day 1 and ANY time during Tuesday should be day two. It seems to me this must be a common problem and thus there is likely an elegant solution. Time zone are a thing for me since I have clients in many different time zones.
UPDATE: I have a solution. It's ugly. I'd be very happy if someone gave me the good looking / elegant / sophisticated version.
convert tProjectStarted to the internet date -- internet date format = Fri, 21 Jun 2024 09:51:36 +0700
put "00:00:00" into word 5 of tProjectStarted
convert tProjectStarted to seconds -- I believe this gets me the start of my day local time in seconds
put the seconds into tNow
return ceiling((tNow - tProjectStarted) / 86400) -- give me the correct day 0.0001 => Day 1 1.0001 => day 2
Bruce
Day of Project (subtracting calendar days
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 84
- Joined: Mon Apr 06, 2020 1:19 pm
- Contact:
Re: Day of Project (subtracting calendar days
Hi Bruce,
here I post a library made by Malte Brill (derBrill) which he has put it into the public domain in 2014.
It has a very complete variety of handlers for I guess for most calendar related problems.
for days between dates you would have to add 1 to the result since you want to include the first date
The complete library is attached here.
Kind regards
Bernd
here I post a library made by Malte Brill (derBrill) which he has put it into the public domain in 2014.
It has a very complete variety of handlers for I guess for most calendar related problems.
for days between dates you would have to add 1 to the result since you want to include the first date
Code: Select all
-- from Malte Brill's libDate
function libDate_DaysBetween pYear1,pMonth1,pDay1,pYear2,pMonth2,pDay2
return libDate_DayNumber(pYear2,pMonth2,pDay2) - libDate_DayNumber(pYear1,pMonth1,pDay1)
end libDate_DaysBetween
-- taken from http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html
function libDate_DayNumber pYear,pMonth,pDay
put (pMonth + 9) mod 12 into pMonth
put pYear - pMonth div 10 into pYear
return 365*pYear + pYear div 4 - pYear div 100 + pYear div 400 + (pMonth*306 + 5) div 10 + ( pDay - 1 )
end libDate_DayNumber
The complete library is attached here.
Kind regards
Bernd
- Attachments
-
- libDate.rev.zip
- (8.52 KiB) Downloaded 493 times
-
- Posts: 84
- Joined: Mon Apr 06, 2020 1:19 pm
- Contact:
Re: Day of Project (subtracting calendar days
Thank you very much Bernd.
I feel like I should know about such things. How / where does one find out about these libraries that exist?
Bruce
I feel like I should know about such things. How / where does one find out about these libraries that exist?
Bruce
Re: Day of Project (subtracting calendar days
Hi Bruce,
Here is Malte's announcement.
viewtopic.php?f=108&t=23885
When I saw your post I remembered the library.
When going the "seconds" way you have to watch out for "daylight saving time changes". Malte calculates the days directly.
Kind regards
Bernd
I don't know. It was announced and referenced here in the forum a couple of times.I feel like I should know about such things. How / where does one find out about these libraries that exist?
Here is Malte's announcement.
viewtopic.php?f=108&t=23885
When I saw your post I remembered the library.
When going the "seconds" way you have to watch out for "daylight saving time changes". Malte calculates the days directly.
Kind regards
Bernd