Announcement

Collapse
No announcement yet.

Simple date problem

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

  • Egbert Zijlema
    replied
    The main problem here, imho, is that Regional Settings in Windows are not always set correctly.
    Partly you have to do that yourself, while running the Control Panel applet for those settings.
    "Good old DOS" did'nt have that problem. To solve your problem, here's a piece of code to run in PowerBasic for Dos (version 3.50)
    Modify your Regional Settings according to the resulting information.

    BTW: For those who don't have PBDOS, please e-mail me at: [email protected] and I'll send you an executable.
    Code:
    '                   Source code: PowerBASIC for DOS
    '
    '           Author: [email protected]
    ' Copyright status: Public Domain
    ' FUNCTIONs to get country code and
    '         country specific delimiters for date, time and numbers
     
    $COMPILE EXE
    ' -----------------------------------------------------------------------
    ' CountryInfo - returns a string with the following information:
    ' First byte (= string's ASCII) is either 0, 1 or 2
    '     0: date format = mdy (American)
    '     1: date format = dmy (European)
    '     2: date format = ymd (Asian or Japanese)
     
    ' Char  8: country specific decimal point
    ' Char 10:                  thousand separator
    ' Char 12:                  date separator
    ' Char 14:                  time separator
      
    FUNCTION CountryInfo AS STRING
      buffer$ = SPACE$(64)                             ' prepare buffer
      REG 8, STRSEG(buffer$)                           ' DS = segment
      REG 4, STRPTR(buffer$)                           ' DX = offset
      REG 1, &H3800                                    ' AX = service
      CALL INTERRUPT &H21
      FUNCTION = buffer$                               ' buffer filled
    END FUNCTION
     
    ' main
    CLS
      buff$ = CountryInfo
      code% = REG(2)
      formt% = ASC(buff$)
      dd$ = MID$(buff$, 12, 1)
      pbDate$ = DATE$
      REPLACE "-" WITH dd$ IN pbDate$
      PRINT "Your country code is: "; TRIM$(STR$(code%))
      PRINT "The date delimiter in your country is: "; CHR$(34, 32); dd$; CHR$(32, 34)
      SELECT CASE formt%
        CASE 0
          PRINT "Date format is: MM DD YYYY"
        CASE 1
          PRINT "Date format is: DD MM YYYY"
          pbDate$ = MID$(pbDate$, 4, 3) + LEFT$(pbDate$, 3) + MID$(pbDate$, 7)
        CASE 2
          PRINT "Date format is: YYYY MM DD"
          pbDate$ = MID$(pbDate$, 7) + dd$ + LEFT$(pbDate$, 3) + MID$(pbDate$, 4, 2)
      END SELECT
      PRINT "So a short date in Windows should look like this: "; pbDate$
    END
    ------------------


    [This message has been edited by Egbert Zijlema (edited July 17, 2000).]

    Leave a comment:


  • Lance Edmonds
    replied
    I fully understand Semen! In NZ, like some (most?) parts of Europe, we use DD-MM-YYYY, not MM-DD-YYYY.

    The problem gets worse when (local) people install Windows and "office" applications... unless they remember to set the Windows locale correctly, importing spreadsheet data containing dates can be quite amuzing, and generates the occasional tech support call! I've had a number of people ring me up asking why Excel does not understand 13-07-2000 is a real date, yet 12-07-2000 is fine...



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    High important information for persons, which live on islands
    On big land is used dd-mm-yyyy format.
    When I receive letters, written in English by guys from Europe, and see date, I always have troubles.
    From one side, in English should be mm-dd.
    From another - native format is dd-mm.
    If day is more 12, no questions. But 07-05-2000 is July, 5 or May, 7 - no idea.



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

    Leave a comment:


  • DorianDarby
    Guest replied
    Hello again!

    I've tried out that function, in both UK and US settings, but it
    works fine all the time. When I had my PC set to US settings,
    I also played around with the time format (AM/PM indicator etc)
    but everything worked fine still.

    Could you email me all of your regional settings, and I'll try
    to figure out what's happening.

    I won't even charge for this customer support issue!

    Take care,

    Dorian

    [email protected]


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

    Leave a comment:


  • DorianDarby
    Guest replied
    Hi Scott,

    I wrote that function for you (my workmate is in Las Vegas at
    the minute, losing serious money!)

    What is the Hex code? The Hex number is the value of the
    first constant, e.g. &H38 is January, and so to make the function
    small I jsut add on the month number to this constant and feed
    it in to the API call. AFAIK it works here in the UK fine, but
    I'll test it again and see what happens.

    Paul should be back in the office Next Monday, so no doubt he'll
    get back to you as well.


    Dorian

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

    Leave a comment:


  • Scott Turchin
    replied
    And it is in the netherlands, no wonder he was having so much trouble....

    OK Now I will have another mod to do

    Thanks!

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Scott --
    If you need DayOfWeek only:
    Code:
          Local szText As Asciiz * 64
          GetDateFormat %LOCALE_USER_DEFAULT, 0, ByVal %Null, "dddd", szText, SizeOf(szText)
          MsgBox szText
    ------------------

    Leave a comment:


  • Egbert Zijlema
    replied
    Scott,

    In some countries, for instance in The Netherlands, a long date is written without a comma between dayname and date,
    for instance "zondag 16 juli 2000" (lit.: Sunday 16 July 2000).
    But whether there's a comma or not, there is always a space.
    So use the space as a delimiter and to be sure there is no comma in the end,
    add this to your code:

    Code:
    FunVar$ = Parse$(tDay, CHR$(32), 1)
    IF RIGHT$(FunVar$, 1) = "," THEN 
      FunVar$ = LEFT$(FunVar$, LEN(FunVar$) - 1)
    END IF
    FUNCTION = FunVar$
    ------------------




    [This message has been edited by Egbert Zijlema (edited July 16, 2000).]

    Leave a comment:


  • Scott Turchin
    replied
    This is what I have used for a long time, can anyone outside the US test this for me?
    It should only return "Sunday" or whatever day it is...


    Scott

    Code:
    Function DayOfTheWeek() Export As String
      Local sTime        As SYSTEMTIME
      Local tDay         As Asciiz * 64
     
      GetLocalTime sTime
      GetDateFormat %LOCALE_USER_DEFAULT,%DATE_LONGDATE,sTime, ByVal %NULL, tDay, 64
      Function = Parse$(tDay,",",1)
    End Function
    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Scott --
    GetDateFormat does all.

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

    Leave a comment:


  • Scott Turchin
    started a topic Simple date problem

    Simple date problem

    I have an associate in another country that was testing my application and ran across some serious flaws in the Day of hte week field...

    So he wrote a new function, but has been unavailable lately.

    So I'm just posting this here to see if anyone can tell me why this returns PM instead of "Sunday" or Monday etc....
    I don't quite understand what the hex number's are doing.
    Previous function worked fine "On our little island" (America)
    hehe...

    At least he has a sense of humor...


    Code:
    Function DayOfTheWeek() Export As String
        '// get date format in "dddd, MMMM dd, yyyy"
        '// e.g. Monday, June 26, 2000
    
        Local uTime         As SYSTEMTIME
        Local lNum          As Long
        Local saDay         As Asciiz * 64
        Local saMonth       As Asciiz * 64
    
        GetLocalTime uTime
        lNum = &H2A + (uTime.wDayOfWeek) -1
        GetLocaleInfo %LOCALE_USER_DEFAULT, lNum, saDay, SizeOf(saDay)
    
        lNum = &H38 + (uTime.wMonth - 1)
        GetLocaleInfo %LOCALE_USER_DEFAULT, lNum, saMonth, SizeOf(saMonth)
        Function = Trim$(saDay & ", " & saMonth & " " & Trim$(Str$(uTime.wDay)) & ", " & Trim$(Str$(uTime.wYear)))
    End Function

    Thanks, there is some urgency to this as the app is already on a bout 10 shareware sites, but luckily only pointing back to MY webserver..


    Scott



    ------------------
    Scott
    mailto:[email protected][email protected]</A>
Working...
X