Announcement

Collapse
No announcement yet.

Wish list and follow up to Scotts date problem

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

  • Wish list and follow up to Scotts date problem

    Now I don't really want to bug PowerBasic but why can't you read the Windows short date for the DATE$ function instead of forcing everyone to an American format ?
    If you can't read the shortdate, at least let us format it to a real date format ie dd/mm/yy (which is pretty universal outside of the USA) since FORMAT$ doesn't like a DATE$ in it.

    Regards

    Adrian Aitken


    ------------------

  • #2
    It's easy to make a function with a desired date format:
    Code:
    #Include "win32api.inc"
    Function LocalDate As String
      Local ST As SystemTime
      GetLocalTime ST
      Function = Format$(ST.WDay,"00") + "-" + _
                 Format$(ST.WMonth,"00")   + "-" + _
                 Format$(ST.WYear,"0000")
    End Function
    
    Function PbMain()
      Print "Date: "; LocalDate
    End Function

    ------------------
    Peter.
    mailto[email protected][email protected]</A>

    [This message has been edited by Peter Lameijn (edited January 21, 2001).]
    Regards,
    Peter

    "Simplicity is a prerequisite for reliability"

    Comment


    • #3
      Thanks Peter, coming from a VB background little things like formatting the date are taken for granted!


      Adrian

      ------------------

      Comment


      • #4
        Adrian,

        Why don't you use the Windows API? It returns exactly what you want.
        BTW: "dd/mm/yy" is not "pretty universal outside the US". Actually there are 3 main short date formats:
        mm/dd/yyyy = American
        dd mm yyyy = European (separator differs per country: slash, hyphen or period)
        yyyy/mm/dd = FarEastern, also referred to as Japanese.

        mm-dd-yyyy (with hyphen instead of slash) is not American but typical Power Basic.
        Code:
        LOCAL szDate AS ASCIIZ * 11, st AS SYSTEMTIME
        GetDateFormat %LOCALE_USER_DEFAULT, %DATE_SHORTDATE, st, "", szDate, SIZEOF(szDate)
        MSGBOX szDate
        ------------------
        mailto:[email protected][email protected]</A>
        www.basicguru.com/zijlema/

        [This message has been edited by Egbert Zijlema (edited January 21, 2001).]

        Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
        http://zijlema.basicguru.eu
        *** Opinions expressed here are not necessarily untrue ***

        Comment


        • #5
          Actually the Japanese use the American date system when dealing with English characters and forms which is often. It looks backward to me because I'm from Australia.

          My 2c worth



          ------------------

          Paul Dwyer
          Network Engineer
          Aussie in Tokyo
          (Paul282 at VB-World)

          Comment


          • #6
            VB's Format-function is versatile,
            This simple function tries to mimic this functionallity.

            Code:
            Function FormatDateTime(ByVal vbDatum As Double,ByVal FormatStr$) As String
            'GetDateFormat LCID,Flag,LpDate,LpFormat,LpDateStr,SizeOfLpDateStr
            'GetTimeFormat LCID,Flag,LpTime,LpFormat,LpTimeStr,SizeOfTimeStr
            'wYear;wMonth;wDayOfWeek;wDay;wHour;wMinute;wSecond;wMilliseconds;
              Local d  As Asciiz * 64
              Local dt As String
              Local st As SYSTEMTIME
              Local Tmp$,FDatum$,FTid$,yy$,mm$,dd$,hh$,mi$,ss$
            '..convert from vbdate
              VariantTimeToSystemTime vbDatum, st
            '..Format output-string....................
              If Len(Trim$(FormatStr$)) Then
               Tmp$ = UCase$(Trim$(Parse$(FormatStr$," ",1)))
               If Instr(Tmp$,"YY") And Instr(Tmp$,"MM") Then FDatum$=Tmp$
               If Instr(Tmp$,"HH") And Instr(Tmp$,"MM") Then FTid$=Tmp$
               Tmp$ = UCase$(Trim$(Parse$(FormatStr$," ",2)))
               If Instr(Tmp$,"YY") And Instr(Tmp$,"MM") Then FDatum$=Tmp$
               If Instr(Tmp$,"HH") And Instr(Tmp$,"MM") Then FTid$=Tmp$
               yy$=Format$(st.wYear,"0000")
               mm$=Format$(st.wMonth,"00")
               dd$=Format$(st.wDay,"00")
               hh$=Format$(st.wHour,"00")
               mi$=Format$(st.wMinute,"00")
               ss$=Format$(st.wSecond,"00")
               If Instr(FDatum$,"YYYY") Then Replace "YYYY" With yy$ In FDatum$
               If Instr(FDatum$,"YY"  ) Then Replace "YY" With Right$(yy$,2) In FDatum$
               If Instr(FDatum$,"MM"  ) Then Replace "MM" With mm$ In FDatum$
               If Instr(FDatum$,"DD"  ) Then Replace "DD" With dd$ In FDatum$
               If Instr(FTid$,"HH"    ) Then Replace "HH" With hh$ In FTid$
               If Instr(FTid$,"MM"    ) Then Replace "MM" With mi$ In FTid$
               If Instr(FTid$,"SS"    ) Then Replace "SS" With ss$ In FTid$
               Function = FDatum$ + " " + FTid$
              Else
               GetDateFormat 0, %DATE_SHORTDATE, st, ByVal %Null, d, 64
               dt = d
               GetTimeFormat 0, 12, st, ByVal %Null, d, 64
               dt = dt & " " & d
               Function = dt
              End If
            End Function
            ------------------
            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Comment


            • #7
              Thanks everyone, I used Peters code but because the application needed the month as a 3 letter code I just added a month() array.
              Egbert, when I said dd/mm/yy what I meant was day month year , regardless of seperators!
              It would still have been nice to just use format$(date,"dd MMM yyyy") though.

              Regards

              Adrian Aitken

              ------------------

              Comment


              • #8
                DATE$ has always returned results in MM-DD-YYYY format. Changing
                this would break a lot of existing code and make it confusing for
                folks who aim to convert the date string into numeric format.
                Considering how little code it takes to rearrange the date into
                the format of your choosing, this is not a likely prospect. It
                may be that we'll see something like a DATE$[(format)] or
                some such addition to a future version of PowerBASIC, though.
                This is on the wish list.

                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment

                Working...
                X