Simpler Datenum - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7) +---- Thread: Simpler Datenum (/showthread.php?tid=336) |
Simpler Datenum - doppler - 05-04-2022 Code: (Select All) a$ = Date$ I wanted to simplify the code with a edit. Messaged up the message big time. So I deleted and retried. If you remember my previous post. You will notice the change after the end select and in each case. This will result in faster and smaller code, with no difference in performance. RE: Simpler Datenum - Pete - 05-04-2022 Nice! This is another reason I love QB64 no-limits memory (system limits). Back in the QJUrassic days, we had to optimize code like crazy to get it work on large apps. For instance, I would have needed to change the way datenum$ is calculated by losing the SELECT CASE and doing something very obfuscated, like this.... datenum$ = _TRIM$(STR$(VAL(MID$("000031060091121152182213244274305335", VAL(month$) * 3 - 2, 3)) + VAL(day$))) datenum$ = MID$("00", LEN(datenum$)) + datenum$ ' Three digit formatting. Pete RE: Simpler Datenum - Pete - 05-04-2022 Actually, I'm going to post this demo to demonstrate how to calculate the day (1-366) in leap year and non-leap year calendar periods. I believe your deo only provides the accumulative days in a leap year event, but correct me if I'm wrong. Code: (Select All) INPUT "month-day-year as 'xx-xx-xxxx': ", a$ Note that 1700, 1800 and 1900 were not a leap year, but 2000 was. I think Steve even has a one-liner for leap year calculation. Anyway, feel free to add any of this info / code to your routine if you like, update /edit your code, etc. I don't get bent because my post no longer represents changes another poster makes, unless of course they are doing it to make me look stupid. My wife takes offense at that.... because it's her job. Pete RE: Simpler Datenum - dcromley - 05-05-2022 It seems like it was just a few days ago that I posted about this https://staging.qb64phoenix.com/showthread.php?tid=65 So I changed it to take into account leap-years. Very interesting. The big "Int" statement starts the year with March, and Jan & Feb get moved to 13 and 14. Then the MOD 365 brings them back. This code has just numerics; no strings. Great fun. Thanks. Code: (Select All) Print "m d", 2022, 2024, 2100, 2400 RE: Simpler Datenum - Pete - 05-05-2022 Ah, there's the one-liner calculation. I've seen it in JavaScript and C, but couldn't remember where I saw it in BASIC either on the dot net or dot rip site. Thanks! Pete RE: Simpler Datenum - doppler - 05-05-2022 No Pete you are right. I said F' leap years. Every year is a leap year. Since I was only using it as a Record # pointer. My way (always a leap year.) I can compare or evaluate year over year records. With out adjust the record number for leap years. I only used case to simplify it for the general beginner. I remember the old days of squeezing out bytes and cycles in assembler. Cycles+(conditional cycles)*(1/freq). And hope to god, the byte count was not more than the 2K sometimes 1K eprom. RE: Simpler Datenum - Pete - 05-05-2022 (05-05-2022, 02:10 PM)doppler Wrote: No Pete you are right. I said F' leap years. Every year is a leap year. Since I was only using it as a Record # pointer. My way (always a leap year.) I can compare or evaluate year over year records. With out adjust the record number for leap years. LOL @F Leap Years. You know me, of all people, I saw that REM statement and thought the "F" stood for "For" Shame on me, I should F'n know better! Also, for a BEGINNER, yes, I totally agree. The SELECT CASE CODE is soooooo much easier to wrap the brain around than parsing a data string. The coolest thing about coding is there are so many roads to our destinations. We just have to be there to help those coders traveling them in the wrong direction. Reminds me of that joke, There's the high road and the low road. I like to take the high one, because there's less traffic. Oh, and I tried some assembly, back in the day, too; but I'd usually finish the aspirin before I'd finish most projects. Yeah, push this ! Now if you will excuse me, I have to go install a Windows f'update. Pete RE: Simpler Datenum - euklides - 05-07-2022 Please show also: https://qb64forum.alephc.xyz/index.php?topic=1559.msg107775#msg107775 RE: Simpler Datenum - doppler - 05-07-2022 Let's throw a monkey wrench into the discussion. Did you account for the missing 10 days? https://www.britannica.com/story/ten-days-that-vanished-the-switch-to-the-gregorian-calendar RE: Simpler Datenum - euklides - 05-08-2022 (05-07-2022, 01:27 PM)doppler Wrote: Let's throw a monkey wrench into the discussion. Did you account for the missing 10 days? Works for dates after october,15, 1582 |