Announcement
Collapse
No announcement yet.
10-char date with USING$ comments
Collapse
X
-
I'm assuming you are talking about this thread since there is no PowerTime in this one.
https://forum.powerbasic.com/forum/u...ing#post803996
Well, there is now PowerTime code.
Code: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
Comment
-
The Windows API function call "GetDateFormat()" is a lot easier than trying to get the USING$ string to work. IMO... make that IMNSHO.
Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Originally posted by Michael Mattias View PostThe Windows API function call "GetDateFormat()" is a lot easier than trying to get the USING$ string to work. IMO... make that IMNSHO.
'Code:%unicode = 1 #INCLUDE "win32api.inc" FUNCTION PBMAIN AS LONG LOCAL st AS systemtime LOCAL lngresult AS LONG LOCAL strDate,strFormat AS WSTRINGZ * 11 strFormat = "MM/dd/yyyy" st.wMOnth = 1 st.wday = 17 st.wyear = 2021 lngResult = GetDateFormat(%LOCALE_USER_DEFAULT,BYVAL 0,BYREF st, BYREF strFormat,BYREF strDate,SIZEOF(strDate)) ? strDate st.wMOnth = 3 st.wday = 2 st.wyear = 2021 lngResult = GetDateFormat(%LOCALE_USER_DEFAULT,BYVAL 0,BYREF st, BYREF strFormat,BYREF strDate,SIZEOF(strDate)) ? strDate END FUNCTION '
'Code:MACRO date10(m,d,y) = USING$("*0*0/*0/##",m,d,y) FUNCTION PBMAIN() AS LONG ? Date10(1,17,2021) ? Date10(3,2,2021) END FUNCTION '
Last edited by Stuart McLachlan; 17 Jan 2021, 04:31 PM.
Comment
-
Code:'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
Comment
-
is a lot easier than
I still like the comment..;
This [USING$=based macro] may work for dates, but I wouldn't want to explain it.
MCM
* for me, anyway!
Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
FWIW.. GetDateFormat() and GetTimeFormat() in Real World Use
ODBC SQL Escaped Date, Time, TimeStamp Functions 9-15-2007
Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
Return 8 or 10-character date with USING$
Code:'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
Comment
Comment