|
Post by honky on Dec 9, 2023 14:14:06 GMT
Good morning, Would there be a means, with: date$ ("4/1/2002") and: date$ ("5/2/2022") To have time between the two in the form: mm/dd/yyyy By passing by: date$ (x) ? And if yes, how ? I tried by dissecting: "4/1/2002" and: "5/2/2022" (20 lines and a big headache afterwards, I am here). If there is a method by dissecting dates, I am also taker.
Thank you for.
|
|
|
Post by Rod on Dec 9, 2023 16:17:58 GMT
I have read this a couple of times. Do you want the answer as mm/dd/yyyy or are you just telling us that the dates are in mm/dd/yyyy format? So is the elapsed time (days) to be answered in the format mm/dd/yyyy or simply number of elapsed days?
|
|
|
Post by honky on Dec 9, 2023 16:26:18 GMT
Time result in "mm/dd/yyyy" format, it's the difficult.
|
|
|
Post by xxgeek on Dec 9, 2023 17:36:14 GMT
Does this help? Does not consider leap years in calculations.
today = date$("4/1/2002") target = date$("5/2/2022")
print "Number of Days Between ";target;" and ";today;" = ";target-today
print "Number of Months between ";target;" and ";today;" = ";(target-today)/12
print "Number of Years betwen ";target;" and ";today;" = ";(target-today)/365
print "Number of Days/Months/Years between ";target;" and ";today;" = ";chr$(13);chr$(13);"Days / Months/ Years";chr$(13);chr$(13);target-today;"/";(target-today)/365*12;"/";(target-today)/365
|
|
|
Post by Rod on Dec 9, 2023 21:28:32 GMT
So a year = 365 days and a month= 365/12 days. Find how many whole years, note the remaining days. Find how many whole months, note the remaining days. To get the remainder, years = int(days/365) remaining days = days-365*years and so to months
|
|
|
Post by honky on Dec 10, 2023 8:41:16 GMT
It's not so simple With "xxgeek" method, Today = "4/5/2023" and Target = "4/5/2024" He gives: 1 Years / 11 MONTHS / 366 Days I would like to see: "1 Year / 0 Month / 0 Days"
For: Today = "4/5/2023" and Target = "4/6/2024" (One Day More) He gives: 1 Years / 11 Months / 367 Days I would like to see: "1 Year / 0 Month / 1 Day"
For: Today = "4/5/2023" and Target = "5/5/2024" (One Month More). He gives: 1 Years / 12 Months / 396 Days I would like to see: "1 Year / 1 Month / 0 Day"
For: Today = "4/5/2023" and Target = "3/5/2024" (One Month Less) He gives: 0 Years / 10 Months / 335 Days
I would like to see: "0 Year / 11 Month / 0 Day"
The days cannot be precise without any scholarships because of the 30 days months, but I don't want the days. a$="4/5/2023": b$="5/5/2024" today = date$(a$): target = date$(b$) print "Today: ";a$;" Target: ";b$ d=target-today: m=int((target-today)/30.6): y=int((target-today)/365) print y;" Years / ";m;" Months / ";d;" Days"
|
|
|
Post by Rod on Dec 10, 2023 10:53:19 GMT
The leap years and such are dealt with in the date$() subtraction. After that we can only deal with years as 365 days, months as 365/12. Provided you accept that limitation then it goes something like this.
a$="4/5/2023": b$="5/5/2024" today = date$(a$): target = date$(b$) print "Today: ";a$;" Target: ";b$
'honky d=target-today: m=int((target-today)/30.6): y=int((target-today)/365) print y;" Years / ";m;" Months / ";d;" Days" print
if today<target then d=target-today else d=today-target print "Elapsed days =";d 'get how many whole years and calculate the remaining days y=int(d/365) : d=d-y*365 print "Years =";y 'get how many whole months in the remaining days and calculate the remaining days m=int(d/(365/12)) : d=d-m*(365/12) print "Months =";m 'we may have a few days left over print "Days =";int(d)
|
|
|
Post by honky on Dec 10, 2023 13:44:21 GMT
If we divide 365 by 12, we obtain the average duration of one month To have the number of months you need 365 / 30.6 (30.58) Your code is well for me
|
|
|
Post by Rod on Dec 10, 2023 17:13:23 GMT
Can you explain that last point a little more. What is the difference between 30.6 and 365/12
|
|
|
Post by xxgeek on Dec 10, 2023 17:27:25 GMT
Ya, sorry guys, I really screwed that up and caused more confusion. Not only the math, but while the rest of the world is using month/day/year I decide to use day/month/year in my code. I'll try harder to 'get with the program' next time.
|
|
|
Post by honky on Dec 11, 2023 8:38:40 GMT
356/12 gives the number of days of the month (on average). 365 / 30.6 gives the number of months, and what we want Finally I did that Note: The code works with a file: donnees.txt "(to be created), in form: "nom_prenom date (dd/mm/yyyy) Validity duration (Nyeards). (Space is a separator).
nomainwin [start] mois$ = "Jan Fév Mar Avr Mai Jun Jui Aou Sep Oct Nov Déc" today$ = date$("mm/dd/yyyy") j = date$(today$) jsem$ = word$("Mar Mer Jeu x Ven Sam x Dim Lun",int((j/7-int(j/7))*10)+1) date$ = jsem$+" "+mid$(today$,4,2)+" "+word$(mois$, val(today$))'+" "+left$(time$(),5) dd$=date$ ann$= right$(date$("mm/dd/yyyy"),4) mo$=left$(date$("mm/dd/yyyy"),2):aa$=mo$:jo$=aa$ jo$=mid$(date$("mm/dd/yyyy"),4,2) a$=jo$;"/";mo$;"/";ann$ ' a$="10/11/2023" if flag = 1 then nbcases = 0 close #main nbmots = 0 casevide = 0 end if WindowWidth = 1300: WindowHeight = 660 UpperLeftX = 40: UpperLeftY = 20 statictext #main.d, a$, 130, 15, 150, 30 statictext #main.statictext1, "Noms", 10, 15, 50, 30 statictext #main.statictext2, "Date Visite (jj/mm/aa)", 340, 15, 300, 30 statictext #main.statictext3, "Validité", 600, 15, 90, 30 statictext #main.statictext4, "Butée (jj/mm/aa)", 720, 15, 200, 30 statictext #main.statictext5, "Alerte 3 Mois", 900, 15, 80, 30 statictext #main.statictext6, "DEPASSE", 1010, 15, 130, 30
statictext #main.statictext7, "Noms", 10, 320, 50, 30 statictext #main.statictext8, "Date Visite (jj/mm/aa)", 340, 320, 300, 30 statictext #main.statictext9, "Validité", 600, 320, 90, 30 statictext #main.statictext10, "Butée (jj/mm/aa)", 720, 320, 200, 30 statictext #main.statictext11, "Reste", 950, 320, 130, 30 ' statictext #main.statictext9, "(Jours +/- 1)", 1030, 15, 200, 30 TEXTEDITOR #main.text, 10, 65, 1260, 250 TEXTEDITOR #main.rest, 10, 350, 1260, 250 ' TEXTEDITOR #main.dep, 10, 520, 1260, 110 MENU #main, "Files", "Save", [save] Open "Visite ";a$ For Window_nf as #main #main, "trapclose [quit]" #main.text, "!font Courier New 16 bold": #main.rest, "!font Courier New 16 bold" #main.d, "!font courier 16 bold" for x=1 to 11 hand$="#main.statictext";str$(x) #hand$ "!font courier 12 bold" next x if flag = 1 then [byPass] dim nom$(1000),liste$(1000),t$(1000),resu$(1000) dim tri$(1000),definitif$(500),k$(1000),temp$(1000) dim tria$(1000),defin$(500),kk$(1000),mot$(1000) [byPass] flag = 0 '--------------- gosub [chargeesp] gosub [aff] gosub [calc] goto [affrest] if ret=1 then ret=0: wait
wait '------------------------------POINT D'ARRET--------------------- [calc] #main.rest, "!cls": #main.text, "!cls" for x=1 to n anndep$=right$(word$(nom$(x),2),4) annfin$=str$((val(anndep$))+val(left$(word$(nom$(x),3),1))) b$=mid$(word$(nom$(x),2),1,2);"/";mid$(word$(nom$(x),2),4,2);"/";annfin$
nom$(x)=word$(nom$(x),1);" ";word$(nom$(x),2);" ";word$(nom$(x),3);" ";b$ '---------debut md=0 ma=val(mid$(a$,4,2)) if ma=12 then [passaa] for a=ma to 12 scan md=md+1 '---mois début next a [passaa] '---------milieu mm=0 if val(mid$(b$,7,4))=val(mid$(a$,7,4))+1 then [passab] for a=val(mid$(a$,7,4)) to val(mid$(b$,7,4)) scan for mb=1 to 12 scan mm=mm+1 '---mois milieu next mb next a [passab] '----------fin mf=0 for mc=1 to val(mid$(b$,4,2)) mf=mf+1 '---mois fin next mc '-----totaux mtot=0 mtot=md+mm+mf '---total mois ann=int(mtot/12) restm=0 restm=md+mf if restm=12 then restm=0 ann=val(mid$(b$,7,4))-val(mid$(a$,7,4)) if val(mid$(a$,4,2))=12 then ann =ann-1 if ann>1 then ag$="ans" if ann<=1 then ag$="an" if val(mid$(word$(nom$(x),4),7,4))=val(mid$(a$,7,4)) and val(mid$(a$,4,2))> val(mid$(word$(nom$(x),4),4,2)) then ann=0: restm=0 end if noma$(x)=word$(nom$(x),1);" ";word$(nom$(x),2);" ";word$(nom$(x),3);" ";_ b$;" ";str$(ann);ag$;" ";"et";" ";str$(restm);"mois" if restm <3 then nom$(x)=word$(nom$(x),1);" ";word$(nom$(x),2);" ";word$(nom$(x),3);" ";b$;" ";"ALERT" if restm <= 0 then rm=val(mid$(a$,4,2))-val(mid$(word$(nom$(x),2),4,2)) nom$(x)=word$(nom$(x),1);" ";word$(nom$(x),2);" ";word$(nom$(x),3);" ";b$;_ " ";"ALERT";" ";"DEPASSE";" ";str$(rm);"Mois" end if next x #main.text, "!cls" gosub [aff] gosub [affrest] return [aff] '--------------------format affichage------------- for x=1 to n if nom$(x)="" then [passfora] nom1$=word$(nom$(x),1): w1$=word$(nom$(x),2): c1$=word$(nom$(x),3): s1$=word$(nom$(x),4) dl$=word$(nom$(x),5): nl$=word$(nom$(x),6): a1$=word$(nom$(x),7): a2$=word$(nom$(x),8) nom$(x) = nom1$ + space$(26-len(nom1$))+_ ' nom w1$ + space$(19-len(w1$))+_ ' date c1$ + space$(9-len(c1$))+_ ' validite s1$ + space$(14-len(s1$))+_ 'butee dl$ +space$(8-len(dl$))+_ ' Alerte nl$ + space$(8-len(nl$))+_' depasse a1$ +space$(3-len(a1$)) ' rest mois ' a2$+space$(12-len(a2$)) 'jours [passfora] next x for x=1 to n #main.text, nom$(x) next x return [affrest] '--------------------format rest------------- for x=1 to n if noma$(x)="" then [passforb] nom1$=word$(noma$(x),1): w1$=word$(noma$(x),2): c1$=word$(noma$(x),3): s1$=word$(noma$(x),4) dl$=word$(noma$(x),5): nl$=word$(noma$(x),6): a1$=word$(noma$(x),7): a2$=word$(noma$(x),8) noma$(x) = nom1$ + space$(26-len(nom1$))+_ ' nom w1$ + space$(19-len(w1$))+_ ' date c1$ + space$(9-len(c1$))+_ ' validite s1$ + space$(13-len(s1$))+_ 'butee dl$ +space$(5-len(dl$))+_ ' reste ans nl$ + space$(3-len(nl$))+_' et a1$ +space$(3-len(a1$)) ' rest mois ' a2$+space$(12-len(a2$)) 'jours [passforb] next x #main.rest, "!font Courier New 16 bold" for x=1 to n #main.rest, noma$(x) next x wait [chargeesp] nn=0: #main.text, "!cls": #main.rest, "!cls" open "donnees.txt" for input as #2 while eof(#2)=0 nn=nn+1 input #2, donn$ if donn$="" then nn=nn-1: goto [passa] [passa] wend close #2 dim nom$(nn+1),noma$(nn+1),nomb$(nn+1): n=0 open "donnees.txt" for input as #2 while eof(#2) = 0 n=n+1 input #2, donn$ if donn$="" then n=n-1: goto [passb] nom$(n) = donn$ [passb] wend close #2 return [save] '------------------------save---------------- gosub [savo] flag = 1 : goto [start] [savo] #main.text, "!contents? string$" open "donnees.txt" for output as #h print #h, string$ close #h return [quit] if da=1 then da=0: close #d if opc=1 then opc=0: close #c if opt=1 then opt=0: close #t Close #main End
|
|
|
Post by Rod on Dec 11, 2023 11:18:53 GMT
If the number of elapsed days is large 30.6 will introduce errors, 365/12 will remain more accurate.
|
|
|
Post by honky on Dec 11, 2023 12:33:19 GMT
The number of days per month cannot be precise by one or the 2nd method. The only way is to set up a test like: if month_number = 1, 3, 5, 7 ...then end month = 31 if month_number = 2, 4, 6, 8 ...then end month = 30 With another test for bisextil years. I had done it, but the nested loops allong the response time too much.
|
|