Announcement

Collapse
No announcement yet.

10-char date with USING$ comments

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

  • 10-char date with USING$ comments

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

  • #2
    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

    Comment


    • #3
      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'

      Comment


      • #4
        wrong thread
        Dale Yarker
        Member
        Last edited by Dale Yarker; 17 Jan 2021, 02:59 AM. Reason: wrong thread
        Dale

        Comment


        • #5
          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


          • #6
            wrong thread
            Dale

            Comment


            • #7
              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".

              Comment


              • #8
                Your purpose fine. I was in wrong place.
                Dale

                Comment


                • #9
                  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


                  • #10
                    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)

                    Comment


                    • #11
                      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


                      Comment


                      • #12
                        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
                        '
                        Stuart McLachlan
                        Member
                        Last edited by Stuart McLachlan; 17 Jan 2021, 05:31 PM.

                        Comment


                        • #13
                          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

                          Comment


                          • #14
                            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!
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              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


                              • #16
                                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

                                Working...
                                X