April 19, 2024, 05:29:11 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Misc Date functions

Started by billhsln, February 05, 2016, 06:37:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

February 05, 2016, 06:37:18 PM Last Edit: February 06, 2016, 12:26:54 PM by billhsln
I needed to do some things with dates and came up with a bunch of little utilities.  Some of these had been done before and some have been added.  Maybe some one can use some of these in their programming efforts.

I did not come up with all the logic, most was pulled from the web, some had to be cleaned up due to my conditions were different then the original programming language the code came from.  I have tested lots of the code.  There still may be a few mistakes and if you find one I would definitely want either a note telling me it messed up or the fix to correct it.

Bill

Program updated with a few more changes.
When all else fails, get a bigger hammer.

Brian

Thanks, Bill,

I always struggle with dates - I'll have a looksee this weekend

Brian

billhsln

I have a couple of fun ones, enter your Birth Date and it will tell you how many days and weeks you have been around and your exact age in Years, Months and Days.

Note: enter date in yyyy-mm-dd format, I expect full ISO date format (in other words, 2016-2-6 will not work, it must be 2016-02-06).


Bill
When all else fails, get a bigger hammer.

Bill-Bo

Bill,

Years ago, in GW-BASIC, I did a program to determine the day you were born on. I had to do a lot of changes to get it to compile and run with IWBasic. In my old one, I could input the date, month, and year on the same line, separated by commas. Could do that here. Later, I might try your way. My two IF line, I had to break up into four. Of course, % for MOD, and other changes. Here's the code, plus, and attachment of it:

CLS
label Start
Def AN$ as String
Def D as int
Def M as int
Def Y as int
def N as int
def DAY as int
INPUT "Day of birth (DD): ", D
INPUT "Month of birth (MM): ", M
INPUT "Year of birth (YYYY): ", Y
IF M = 1 THEN M = 13
if M = 13 then Y = Y - 1
IF M = 2 THEN M = 14
if M = 14 then Y = Y - 1
N = D + (2 * M) + INT((3 * (M + 1)) / 5) + Y + INT(Y / 4) - INT(Y / 100) + INT(Y / 400) + 2
DAY = N % 7
IF DAY = 1 THEN PRINT "You were born on a Sunday."
IF DAY = 2 THEN PRINT "You were born on a Monday."
IF DAY = 3 THEN PRINT "You were born on a Tuesday."
IF DAY = 4 THEN PRINT "You were born on a Wednesday."
IF DAY = 5 THEN PRINT "You were born on a Thursday."
IF DAY = 6 THEN PRINT "You were born on a Friday."
IF DAY = 0 THEN PRINT "You were born on a Saturday."
input "Would like to do another date (N?Y)? ",AN$
If AN$ = "Y" or AN$ = "y" then goto Start
DO: UNTIL INKEY$ = "N" or "n"
END


Now, in the formulae for these type of programs, January is the 13th month of the previous year, and February if the 14th month of the previous year. This done by the program. You enter the date as the actual date. Like for 6 Feb, 2016, the program is going to compute for the 6th day of the 14th month of 2015. Sounds odd, but that's how it works.

Bill


billhsln

I remember something about March = 3, April = 4, ..., Jan = 13 and Feb = 14, but the algorithm in my code works just with passing along the '1956-04-07'.  I validated it with some other sites that do those kinds of calculations, but don't give you how they did it. 

Will add Day you were born, just another fun thing.  Might even look up the old (? not sure what to call it), Saturday's Child ..., Sunday's Child ....  Need to look that up.

Just one of those little fun exercises in programming.

Bill
When all else fails, get a bigger hammer.