Announcement

Collapse
No announcement yet.

10-char date with USING$ comments

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mike Doty
    replied
    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

    Leave a comment:


  • Michael Mattias
    replied
    FWIW.. GetDateFormat() and GetTimeFormat() in Real World Use

    ODBC SQL Escaped Date, Time, TimeStamp Functions 9-15-2007

    Leave a comment:


  • Michael Mattias
    replied
    is a lot easier than
    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.

    MCM
    * for me, anyway!

    Leave a comment:


  • Mike Doty
    replied
    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
    Attached Files

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Michael Mattias View Post
    The Windows API function call "GetDateFormat()" is a lot easier than trying to get the USING$ string to work. IMO... make that IMNSHO.
    So, it's your not so humble opinion that
    '
    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
    '
    is a lot easier than
    '
    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.

    Leave a comment:


  • Stuart McLachlan
    replied
    Originally posted by Mike Doty View Post
    This may work for dates, but I wouldn't want to explain it.
    I was hoping you would. I can't grasp how it works


    Leave a comment:


  • Mike Doty
    replied
    Thanks MIchael, I will check it out.

    This may work for dates, but I wouldn't want to explain it.
    ? USING$("*0*0/*0/##",1,17,2021) '01/17/2021

    MACRO date10(m,d,y) = USING$("*0*0/*0/##",m,d,y)

    Leave a comment:


  • Michael Mattias
    replied
    The Windows API function call "GetDateFormat()" is a lot easier than trying to get the USING$ string to work. IMO... make that IMNSHO.

    Leave a comment:


  • Dale Yarker
    replied
    Your purpose fine. I was in wrong place.

    Leave a comment:


  • Stuart McLachlan
    replied
    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".

    Leave a comment:


  • Dale Yarker
    replied
    wrong thread

    Leave a comment:


  • Mike Doty
    replied
    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

    Leave a comment:


  • Dale Yarker
    replied
    wrong thread
    Last edited by Dale Yarker; 17 Jan 2021, 01:59 AM. Reason: wrong thread

    Leave a comment:


  • Mike Doty
    replied
    It works, but I'm having difficutly working out how
    Keeping me honest, modified title/caption.
    Yes, it is a tricky one.
    Code:
    MACRO date10(m,d,y) = USING$("*0*0/*0/##",m,d,y)
    FUNCTION PBMAIN () AS LONG
      ? date10(m&,d&,y&) '00/00/0000
    ND FUNCTION'

    Leave a comment:


  • Stuart McLachlan
    replied
    Not necessarily 10 byte. 10 character?

    Local strDate as WSTRING
    strDate = Date10(1,17,2021)

    It works, but I'm having difficutly working out how

    Leave a comment:


  • Mike Doty
    started a topic 10-char date with USING$ comments

    10-char date with USING$ comments

    Source: https://forum.powerbasic.com/forum/u...ate-with-using
    Last edited by Mike Doty; 17 Jan 2021, 01:01 AM.
Working...
X