Source language: Translate to:

Leap Year Logic

General questions about NeoBook

Moderator: Neosoft Support

Leap Year Logic

Postby BRobinsonS » Sat Apr 18, 2015 12:48 pm

I am attempting to allow for leap years with an app that I have a button that adds 1 year (of membership) to a date in DBPro .
I use a SubStr to get the last 4 digits of format (MM/DD/YYYY) (i.e. year from date).
Then if it is a leap year then add 366 instead of 365 for regular year.
Not sure why the First part of IFEx doesn't pick up leap year.
Perhaps there is a better way.

Code: Select all
SubStr "[AddrBook.Contacts.CancelDate]" "7" "4" "[YearStr]"

DateToNum "[AddrBook.Contacts.CancelDate]" "Default" "[DateNum]"
.AlertBox "Date Number" "Number of Date [DateNum]"

IfEx "[YearStr]=2016 OR [YearStr]=2020"
 NumToDate "[DateNum]+366" "Default" "[AddrBook.Contacts.CancelDate]"
Else
 NumToDate "[DateNum]+365" "Default" "[AddrBook.Contacts.CancelDate]"
EndIf
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 340
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada

Re: Leap Year Logic

Postby BRobinsonS » Sat Apr 18, 2015 2:06 pm

This works if I use 2015, 2019,2023,... etc for Leap Year .
Realized by logic mistake.
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 340
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada

Re: Leap Year Logic

Postby Gaev » Sat Apr 18, 2015 2:12 pm

Brian:

I am attempting to allow for leap years with an app that I have a button that adds 1 year (of membership) to a date in DBPro .
Then if it is a leap year then add 366 instead of 365 for regular year.

This logic will result in the following new Cancel Dates ...

January 17, 2015 ---> January 17, 2016
February 28, 2015 ---> February 28, 2016
March 1, 2015 ---> February 29, 2016
September 1, 2015 ---> August 31, 2016

January 17, 2016 ---> January 17, 2017
February 28, 2016 ---> February 28, 2017
February 29, 2016 ---> March 1, 2017
March 1, 2016 ---> March 2, 2017
September 1, 2016 ---> September 2, 2017

... is this what you want ? ... decide what you want in each case ... and post here.


Not sure why the First part of IFEx doesn't pick up leap year.

You don't say what Database you are using ... if it is MS Access ... and you are running this in Canada ... this may be the problem ...
Code: Select all
DateToNum "[AddrBook.Contacts.CancelDate]" "Default" "[DateNum]"

... System Default for Canada is dd/mm/yyyy ... Access handles ALL date fields in American format mm/dd/yyyy

Place AlertBox commands to verify the values of CancelDate and [YearStr] just before the IfEx ... and tell us what it reported.

Only other thing I can suggest is to use rounded brackets to separate the two conditions ...
Code: Select all
IfEx "([YearStr] = 2016) OR ([YearStr] = 2020)"
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Leap Year Logic

Postby BRobinsonS » Sat Apr 18, 2015 3:08 pm

The code I have been using just added one year to membership.
I just need to allow for leap years.

So 12/31/2014 becomes 12/31/2015
but 12/31/2015 became 12/30/2016

Need to add extra day for leap year.
I am using MS Access and date format MM/DD/YYYY (my preference)

Seems to work the way I want if I use Year = 2015 or Year 2019 etc because next year would be a leap year.
If it doesn't I'll be back.

I will add the round brackets.
Thanks again for responding.
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 340
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada

Re: Leap Year Logic

Postby Gaev » Sat Apr 18, 2015 3:55 pm

Brian:

The code I have been using just added one year to membership.
I just need to allow for leap years.

So 12/31/2014 becomes 12/31/2015
but 12/31/2015 became 12/30/2016

It is not as simple as "adding one day" for "all dates in a leap year" ... it depends on what side of February 29 you are ... the bolded dates are the ones that would be in error with your logic ... your logic MUST account for "month and year" AND "years before and during leap years".

So again, are the examples of posted results "what you want" or "something else" ? ... can't devise a solution if you don't have a precise specification of the requirement.

I am using MS Access and date format MM/DD/YYYY (my preference)

That is the ONLY format MS Access supports !!!

So, if you are using "Default" in your DateToNum in Canada, it WON'T work !!!

Seems to work the way I want if I use Year = 2015 or Year 2019 etc because next year would be a leap year.

Try dates before, during and after February, 29 ... leap and non leap years.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Leap Year Logic

Postby BRobinsonS » Sat Apr 18, 2015 5:28 pm

My apology. I wasn't clear.

This is a membership application where memberships expire on the December 31 of each year unless they renew.
So I am only interested in 12/31/YYYY appearing correctly.
The simpler version of my code would show 12/30/2016 for leap year.
So I only need to adjust the one day to get 12/31/2016 which I now believe I can.

Again, my apology for not making this clear.
Brian Robinson
'When all else fails, try again!'
www.ComputerSoftwareSystems.com
User avatar
BRobinsonS
 
Posts: 340
Joined: Sun Sep 25, 2005 9:00 pm
Location: Ontario, Canada


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 6 guests