Spécial ! |
Version mobile de l'aldweb Site m.aldweb.com Ni Français, ni Anglais ?Essayez donc l'un de ces drapeaux :
|
|
Météo / Spam / www |
Météo Lyon
aldweb contre le SPAM
|
|
|
|
|
|
|
- Forum - iziBasic
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Sujet n° 1356 |
DateDiff Function |
le 01/02/2006 @ 11:35 par André
|
I am looking for a way to calculate the number of actual days between two dates. Anybody have a function or source code I can use? |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 1 -------- le 01/02/2006 @ 17:03 par Nevin
visiteur |
I have a built a timer that I use in a few programs from the TIME$ function a similar program could be made using DATE$. The code for my timer is fairly long. I use CHARS (c!t, n!n) to pull individual characters out of the string given by TIME$. Then I convert them to numerical values with VAL and then use some basic math to convert and combine them into a useable time value. I will give you my code if you can't figure it out, but I am sure that Aldweb or Khertan have an easier solution. I am just a newbie. Nevin |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 2 -------- le 02/02/2006 @ 20:24 par aldweb
visiteur |
Khertan should come to the rescue pretty soon...
Cheers, aldweb |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 3 -------- le 02/02/2006 @ 20:52 par Khertan
visiteur |
Héhé ... two seconds ... i must dig in my backup to find it :)
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 4 -------- le 02/02/2006 @ 21:07 par Khertan
visiteur |
Well i can't found it ... maybe on some general backup ... but i can t access it today ... my linux isn't totally configurated yet ...
but i know this method was very slow, and take 2100 line of code ... not very well optimized but entirely in iziBasic ...
But i can send you tommorrow an pp applet that do that more efficiently ...
in 20 or 30 lines of codes :)
just one things, do you want to count entire days only ? or with fraction ? :)
See you later ... i ll do that tomorrow morning in public transport :) |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 5 -------- le 03/02/2006 @ 05:15 par Nevin
visiteur |
Here is some source code for a short program that I developed to access count days through Izibasic. Note: You will need to somehow save the start and end time in Saved Prefs for it to work for practical applications as you probably will not leave your handheld running the same app for days at a time.
Code Start: ' DATE.ibas {CREATORID "DATE"} {VERSION "1.0"} '{MINOSVERSION "3.0"} '{PARSER OFF} '{KEYEVENTS OFF} '{SECUREFILES ON}
BEGIN 'START DAY A$=DATE$ 'Day B$=CHAR$(A$, 2) B=VAL(B$) 'Ten Day C$=CHAR$(A$, 1) C=VAL(C$) 'TOTAL DAYS START D=C*10+B PRINT "You started on the" PRINT D USING 0 PRINT "of the month." WAIT
REPEAT Z=DOEVENTS E$=DATE$ 'Day F$=CHAR$(E$, 2) F=VAL(F$) 'Ten Day G$=CHAR$(E$, 1) G=VAL(G$) 'TOTAL DAYS START H=G*10+F 'Account for start near the end of the month IF D>H THEN H=H+31 ENDIF 'Calculate the difference between start and finish time I=H-D 'Display elaped days. PRINT "There have been" PRINT I USING 0 PRINT "days since it started." IF I>15 THEN GOSUB _EXPIRED ENDIF PRINT "Type Exit to end!" PRINT "Anything else to check again." INPUT X$ IF X$="Exit" THEN Z=-1 ENDIF UNTIL Z=-1 END
_EXPIRED: 'Makes expired in 15 days. PRINT "15 days is up!" END
Code End
You can download this and my other Timer program and source code from : http://www.morrisonmuscle.com/software.htm I am not sure if this is what you are looking for, but they can work well for handling simple time/timer needs in Izibasic. Nevin |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 6 -------- le 04/02/2006 @ 17:23 par aldweb
visiteur |
Nevin,
If you just want to test for a trial period, you better take it easy with a small routine that would roughly estimate all months to be 31 days and add the number of current days on top of 31 minus start day if ever current month is 1 over start month, this for a trial period minor than one month.
Cheers
@+ aldweb |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 7 -------- le 05/02/2006 @ 01:10 par Nevin
visiteur |
Yeah, I know that the 31 day thing was not perfect. I just did not want to take the time to account for the rare case. I was a little lazy. I was just making the program as a small example of how it could be done. I know with a little more code I could have made it better. |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Réponse n° 8 -------- le 05/02/2006 @ 20:42 par aldweb
visiteur |
A good code is one that works A better code usually comes with unexpected bugs
So your code is excellent
@+ aldweb |
|
|
sujet actif
sujet clos
Important!
Nouveau message -
Rectifier message
Clôturer sujet
Remonter
|
|
|
|
|
|