You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
'Pass year 0-99 return 8-character date
'Pass year 1000-9999 return 10-character date
MACRO mydate(month,day,year) = USING$("*0*0/*0/*0",month,day,year)
FUNCTION PBMAIN AS LONG
? mydate(1,18,21) '01/18/21
? mydate((1,18,2021) '01/18/2021
END FUNCTION
Um, you can write the "Date10" function as a MACRO or FUNCTION using either USING$ or GetDateFormat().
I still like the comment..;
This [USING$=based macro] may work for dates, but I wouldn't want to explain it.
I think that is because it's easy* to mix up the formatting strings for USING$() with the formatting strings for FORMAT$()... which are not always the same.
'Mask for 3 2-digit placeholders *A *B *C plus ## for 3rd field which needs 4-digits.
'When first non-mask characters are encountered they are placed after 1st placeholder.
'When second non-mask characters are encountered they are placed after 2nd placeholder.
'The character after * in each of the 3-field masks is used to left-fill each field respectively with A or B or C.
'MACRO date10(m,d,y) = USING$("*0*0/*0/##",m,d,y) don't leave home without it.
'Another way this could be done is use "##/##/####" and replace " " with "0" in mystring.
'I have no idea if building the date string would be more efficient than the using statement.
'If this is wrong, "I didn't do it, nobody saw me do it, you can't prove anything."
FUNCTION PBMAIN AS LONG
DIM s(1 TO 2) AS STRING
s(1) = USING$("*A*B*C##",1,2,3) '[B]A1B2CCC3[/B]
s(2) = USING$("*A*B / *C / ##",1,2,3) [B]'A1 / B2 / CCC3[/B]
? JOIN$(s(),$CR),,"Data only and Data with '/'"
END FUNCTION
We seem to be talking at cross purposes, the thing that I am having difficulty working out is how the mask in USING$("*0*0/*0/##",m,d,y) works to produce something like "03/04/2020".
FUNCTION PBMAIN () AS LONG
LOCAL y,m,d AS LONG
LOCAL o AS IPOWERTIME
o = CLASS "PowerTime"
y = 2021
m = 1
d = 16
o.newdate(y,m,d)
IF o.year = y AND o.month = m AND o.day = d THEN [B]'check date validity[/B]
? o.datestringlong,,"Valid"
ELSE
? "Bad date"
END IF
END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: