|
Post by tenochtitlanuk on Nov 1, 2018 17:38:15 GMT -5
On Yahoo Groups there's been a thread in which date$ behaved strangely with 'and' conditional. For me the varied forms of date$( were just right to calculate UNIX dates for my tide-predictor.
I had to use the first version, as the second errors out. The third version works...
'#1 works OK d$ = date$( "mm/dd/yyyy") UnixTimeNowSecs =( date$( d$) -date$( "01/01/1970")) *24 *60 *60 +time$( "seconds") ' -3600 -adjust for British Summer Time print "<"; UnixTimeNowSecs; ">"
#2 FAILS UnixTimeNowSecs =( date$( "mm/dd/yyyy")) -date$( "01/01/1970")) *24 *60 *60 +time$( "seconds") ' -3600 -adjust for British Summer Time 'rint "<"; UnixTimeNowSecs; ">" here
'#3 works OK UnixTimeNowSecs =( date$( chr$( 34) +date$( "mm/dd/yyyy") +chr$( 34)) -date$( "01/01/1970")) *24 *60 *60 +time$( "seconds") ' -3600 -adjust for British Summer Time print "<"; UnixTimeNowSecs; ">"re
|
|
|
Post by Brandon Parker on Nov 1, 2018 21:27:23 GMT -5
In my opinion the Date$() function in Liberty BASIC is kind of "Super-Overloaded"; it's offers a large array of possibilities for working with dates. I believe I have run into this in the past at some point and I think it is either a parsing error or type casting/ conversion error on the back-end.
In order to get #2 to work as expected you need to pass the date$("mm/dd/yyyy") back to the date$() function to return the number of days that values is since that is what date$("01/01/1970") is actually doing (all based on LB's value for when "time started"). The hiccup is that when you pass something to the date$() function like this is should be a string value and that is not exactly what date$() seems to return. So.....just wrap the date$("mm/dd/yyyy") in str$() and return it just as is shown below.
UnixTimeNowSecs =( date$(str$(date$( "mm/dd/yyyy"))) -date$( "01/01/1970")) *24 *60 *60 +time$( "seconds") ' -3600 -adjust for British Summer Time Print "<"; UnixTimeNowSecs; ">"
I hope this helps although I cannot completely explain the inner workings completely since I'm not privy to it.
{:0)
Brandon R. Parker
|
|
|
Post by tsh73 on Nov 4, 2018 15:29:26 GMT -5
So.
d$ = date$( "mm/dd/yyyy") print date$( d$) works, while
print date$( date$( "mm/dd/yyyy")) is not. I agree this is a bug. But. LB has actually special command to get number of days for "NOW" and it is
print date$("days")
|
|
|
Post by Brandon Parker on Nov 4, 2018 19:54:59 GMT -5
I am 99% positive the issue arises because the Date$() function is expecting a literal string to be passes to it. The Date$() function is returning, at least from what it looks like to me, a pointer to a string. I'm sure this could be classified as a minor bug if need be, but it really isn't stated in the documentation that you can feed the return value of the Date$() function as a parameter to the Date$() function itself. That is the part that people just make an assumption about given that it prints out as a string and can be assigned to a string variable. When assigning the Date$() function to a PTR member of a Struct you get the pointer to the string being held in the Struct member; like below.... Struct myStruct, varPtr As ptr
Print date$("mm/dd/yyyy") var$ = date$("mm/dd/yyyy") Print date$(var$)
'Print date$(date$("mm/dd/yyyy")) Print date$(str$(date$("mm/dd/yyyy")))
myStruct.varPtr.struct = date$("mm/dd/yyyy")
Print myStruct.varPtr.struct Print Winstring(myStruct.varPtr.struct)
Print date$(Winstring(myStruct.varPtr.struct)) For me, this is the bigger of the issues..... Since there are some "things" that could be improved with the Date$() function this one should be the first thing on the agenda. Once again, I'm betting it is because the function is overload like crazy and there is something that just requires tweaking with it behind the scenes. Without further rambling, here is my main issue with it.... You can actually store a string value into a numerical variable using the Date$() function.... I'm pretty sure this has been brought up previously... 'Storing a string from the Date$() function into a numerical variable var = date$("mm/dd/yyyy") 'Print said variable and tadaaaaa; it actually points to the string date Print var 'Print the value using the str$() function and it is returned with single-quotes surrounding it Print str$(var) 'store the numerical var variable into a string var$ variable and print it; stores with the single-quotes var$ = str$(var) Print var$ For me these things are not huge issues though.... {:0) Brandon R. Parker
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Dec 26, 2018 13:19:23 GMT -5
Hello,
I have a question about date$ I have a string betaaldatum$ what gives for example "2018-12-21" Now I want this date + 14 days. What should give "2019-01-04" How can I made this?
Thanks!!
|
|
|
Post by tsh73 on Dec 26, 2018 13:38:38 GMT -5
'I have a string betaaldatum$ what gives for example "2018-12-21" 'Now I want this date + 14 days. What should give "2019-01-04"
betaaldatum$="2018-12-21" 'sorry, doesn't work. 'needs format "mm/dd/yyyy" dt$=word$(betaaldatum$,2,"-")+"/"+word$(betaaldatum$,3,"-")+"/"+word$(betaaldatum$,1,"-") dtOld= date$(dt$) dtNew$ = date$(dtOld+14) dtOut$=word$(dtNew$,3,"/")+"-"+word$(dtNew$,1,"/")+"-"+word$(dtNew$,2,"/")
print betaaldatum$ print dtOut$
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Dec 26, 2018 15:19:17 GMT -5
Thanks tsh73 Now its working. I dont understand this line well: dt$=word$(betaaldatum$,2,"-")+"/"+word$(betaaldatum$,3,"-")+"/"+word$(betaaldatum$,1,"-") First 2 and than 3 and as last 1. How does it work?
I use it to get the payment info out of a ubl invoice(xml) and safe it in a file. With a sepa file in excel I can make a sepa file wich I can uploud to the internet banking
dim a$(30000) i =0 open "c:\ubl.csv" for input as #readFile while not( eof( #readFile)) inputcsv #readFile, a$(i) 'print a$(i) i =i +1 wend close #readFile
naam$ = "cac:PartyName"
a=0 while naam$ <> a$(a) and a <30000 a = a + 1 wend naamafz$ = a$(a+4) print naamafz$
iban$ = "cac:PayeeFinancialAccount"
b=0 while iban$ <> a$(b) and b <30000 b = b + 1 wend banknr$ = a$(b+4) print banknr$
'bic$ = "cbc:ID schemeName=BIC"
'c=0 'while bic$ <> a$(c) and c <30000 c = c + 1 'wend 'bicnr$ = a$(c+1) 'print bicnr$
factuur$ = "cac:AdditionalDocumentReference"
d=0 while factuur$ <> a$(d) and d <30000 d = d + 1 wend factuurnr$ = a$(d+4) print factuurnr$
bedrag$ = "cbc:PayableAmount currencyID=EUR"
e=0 while bedrag$ <> a$(e) and e <30000 e = e + 1 wend bedragincl$ = a$(e+1) print bedragincl$
betaaldat$ = "cbc:PaymentDueDate"
f=0 while betaaldat$ <> a$(f) and f <30000 f = f + 1 wend betaaldatum$ = a$(f+1) print betaaldatum$ dt$=word$(betaaldatum$,2,"-")+"/"+word$(betaaldatum$,3,"-")+"/"+word$(betaaldatum$,1,"-") dtOld= date$(dt$) dtNew$ = date$(dtOld+21) dtOut$=word$(dtNew$,3,"/")+"-"+word$(dtNew$,1,"/")+"-"+word$(dtNew$,2,"/")
print betaaldatum$ print dtOut$
open "c:\invoer SEPA-CT.txt" for append as #1 print #1, "your IBAN,your BIC,your name,"+banknr$+","+bicnr$+","+naamafz$+","+bedragincl$+",Factuurnr:"+factuurnr$+","+dtOut$
close #1
|
|
konijn
Junior Member
Posts: 96
|
Post by konijn on Dec 26, 2018 15:27:20 GMT -5
Ubl file. The <> repleaced with , and the "removed
|
|
|
Post by tsh73 on Dec 26, 2018 16:01:52 GMT -5
Your data goes if the form betaaldatum$="2018-12-21" that is yyyy-mm-dd But for LB date$ to work it should be in the form mm/dd/yyyy So this line does the conversion. word$(a$, i) gives i-th word from line a$, delimited with spaces word$(a$, i, d$) gives i-th word from line a$, delimited with d$. So I used "-" as a delimiter and get 2nd (mm), 3rd (dd) and 1st (yyyy) words of yyyy-mm-dd (that is of 2018-12-21). And glued them together with (+), putting (/) in between to get mm/dd/yyyy.
|
|