Sorry, an error occurred while loading the content.

## Re: 1000 days

Expand Messages
• or try http://www.timeanddate.com/date/duration.html Derek Sharp
Message 1 of 7 , Feb 1, 2011
or try

http://www.timeanddate.com/date/duration.html

Derek Sharp

--- In libertybasic@yahoogroups.com, "green8819" <green8819@...> wrote:
>
> By simple arithmetic, 1000 days is about 2years 8 months 26 days;
> but it's not precise.
> Is there a more accurate conversion method?
> Thanks.
>
• What outcome are you looking for? I m not sure I understand the question. print date\$(date\$( days )+1000)
Message 2 of 7 , Feb 1, 2011
What outcome are you looking for? I'm not sure I understand the question.

print date\$(date\$("days")+1000)

--- In libertybasic@yahoogroups.com, "green8819" <green8819@...> wrote:
>
> By simple arithmetic, 1000 days is about 2years 8 months 26 days;
> but it's not precise.
> Is there a more accurate conversion method?
> Thanks.
>
• ... Mike, This should just be a matter of using 3 dates, Initial, Ending, and Current, and doing some date math with the date\$() function. When creating the
Message 3 of 7 , Feb 1, 2011
--- In libertybasic@yahoogroups.com, "green8819" <green8819@...> wrote:
>
> By simple arithmetic, 1000 days is about 2years 8 months 26 days;
> but it's not precise.
> Is there a more accurate conversion method?
> Thanks.
>
Mike,

This should just be a matter of using 3 dates, Initial, Ending, and Current, and doing some date math with the date\$() function.

When creating the event and saving it to the database, use Initial date and Ending date. See Rod's example for simple way to get Initial and Ending dates.

Then, when retrieving the event record, use the Current date and the Ending date to calc the remaining days.

In the help file, see this example under DATE\$():
'--code (watch for line breaks)
today = date\$("days")

target = date\$("12/25/2003") 'subsititute current year and desired holiday

print "Shopping days left: ";

print target - today
'--end code
• ... How about the following? ---code start (watch for line wraps) StartDate\$ = 02/15/2010 StartDays = date\$(StartDate\$) EndDays = StartDays + 1000
Message 4 of 7 , Feb 2, 2011
> >
> > By simple arithmetic, 1000 days is about 2years 8 months 26 days;
> > but it's not precise.
> > Is there a more accurate conversion method?
> > Thanks.
> >

How about the following?

'---code start (watch for line wraps)

StartDate\$ = "02/15/2010"
StartDays = date\$(StartDate\$)

EndDays = StartDays + 1000
EndDate\$ = date\$(EndDays)

StartDay = val(word\$(StartDate\$, 2, "/"))
StartMonth = val(word\$(StartDate\$, 1, "/"))
StartYear = val(word\$(StartDate\$, 3, "/"))

EndDay = val(word\$(EndDate\$, 2, "/"))
EndMonth = val(word\$(EndDate\$, 1, "/"))
EndYear = val(word\$(EndDate\$, 3, "/"))

' calculate whole years
NextYear = StartYear
TotalYears = 0

while date\$("12/31/"; NextYear + 1) < EndDays
NextYear = NextYear + 1
TotalYears = TotalYears + 1
wend

' add remaining months of start year to total months
TotalMonths = 12 - StartMonth

' add elapsed months of end year to total months
TotalMonths = TotalMonths + EndMonth

' may be convert months to years
' TotalYears = TotalYears + int(TotalMonths / 12)
' TotalMonths = TotalMonths mod 12

' add remaining days of start month to total days
TotalDays = GetDaysOfMonth(StartMonth, StartYear) - StartDay

' add elapsed days of end month to total days
TotalDays = TotalDays + EndDay

Print "Start Date ..... "; StartDate\$; " ... "; StartDays
Print "End Date ....... "; EndDate\$; " ... "; EndDays

Print "Total Years .... "; TotalYears
Print "Total Months ... "; TotalMonths
Print "Total Days ..... "; TotalDays
end

function GetDaysOfMonth(Month, Year)
for GetDaysOfMonth = 31 to 28 step -1
if date\$(Month; "/"; GetDaysOfMonth; "/"; Year) > 0 then exit for
next
end function

'---code end

---
Stefan Pendl
http://stefanpendl.runbasichosting.com/

Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

Books at http://www.lulu.com/ and http://www.amazon.com/
Alyce Watson ... APIs for Liberty BASIC
Carl Gundel .... Beginning Programming with Liberty BASIC

Windows 7 Home Premium 64-bit RTM
AMD Turion X2 RM-70 2GHz, 4GB RAM
• If it is the elapsed time to a pending event why not keep it really simple. The lowest common denominator you can get from DATE\$() maths is days. The number of
Message 5 of 7 , Feb 2, 2011
If it is the elapsed time to a pending event why not keep it really simple. The lowest common denominator you can get from DATE\$() maths is days. The number of days will be very accurate, it only gets complicated if you want to convert that back to months, weeks, days. It is very easy if you just convert it back to weeks. Divide it by 7, there are always seven days in a week no matter how the months or leap years fall. Everyone knows 52 weeks make a year and by it's nature a calendar wont be listing more than a year ahead. So either print the number of days to the event or the number of weeks to the event. Or both.

days = 22
print "Weeks ";int(days/7);" Days ";days mod 7
• ... Well, here in Europe we end up with 52 or 53 weeks a year, since the first week of the year is always the week, which includes January 4th, so weeks are
Message 6 of 7 , Feb 2, 2011
>
> If it is the elapsed time to a pending event why not keep it
> really simple. The lowest common denominator you can get from
> DATE\$() maths is days. The number of days will be very
> accurate, it only gets complicated if you want to convert
> that back to months, weeks, days. It is very easy if you just
> convert it back to weeks. Divide it by 7, there are always
> seven days in a week no matter how the months or leap years
> fall. Everyone knows 52 weeks make a year and by it's nature
> a calendar wont be listing more than a year ahead. So either
> print the number of days to the event or the number of weeks
> to the event. Or both.
>
> days = 22
> print "Weeks ";int(days/7);" Days ";days mod 7
>

Well, here in Europe we end up with 52 or 53 weeks a year, since the first week of the year is always the week, which includes
January 4th, so weeks are not so simple either, see Wikipedia for stranger calculations.

Calculation of years, months and days is possible, so we can have things listed as we like.

---
Stefan Pendl
http://stefanpendl.runbasichosting.com/

Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

Liberty BASIC Bug Tracker ... http://libertybasicbugs.wikispaces.com/

Books at http://www.lulu.com/ and http://www.amazon.com/
Alyce Watson ... APIs for Liberty BASIC
Carl Gundel .... Beginning Programming with Liberty BASIC

Windows 7 Home Premium 64-bit RTM
AMD Turion X2 RM-70 2GHz, 4GB RAM
Your message has been successfully submitted and would be delivered to recipients shortly.