Announcement

Collapse
No announcement yet.

How to assess user's date format?

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

  • How to assess user's date format?

    As the occasional programmer, I needed a quick little app to create lists of dates for work that I do. The app must display certain dates in a multi-select listbox in the yyyy-mm-dd format. (I posted some of my multi-select routines in: http://www.powerbasic.com/support/pb...ad.php?t=40948)

    I wrote it in FireFly, and it works fine on my XP. However, when I ran it on another XP, I found my dates truncated and containing extraneous characters. I tried to change the short and long formats on the second machine, but that didn't seem to help.

    I think this has to do with conflicts between my development machine, where I have the date format set to yyyy-mm-dd (eg: 2009-07-01), the way that the DatePick32 control sees the LONGFORMAT, and the way that the other machine has its dates set.

    So I'm wondering how to make my app read the current user's date formats?

    I'm presuming that once I know what they're using, I can reliable predict which reformatting I'll need so that my app can display all dates as yyyy-mm-dd.

    Thanks,
    -John

  • #2
    >the way that the DatePick32 control sees the LONGFORMAT

    Using the SysDateTimePick32 control, you can make all dates independent of the user LONG/SHORT formats by using the DTM_SETFORMAT message to specify the format you want in the control.
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Great! Thanks, I'll try that.

      Meanwhile, I tried to check the user's date format by checking the position of month, day, and year from PB's DATE$, but I gather that it is independent of the user's profile settings... Today I saw something in a source code snippet about a LOCALE setting, and I'll spend some time tomorrow researching that... Any other suggestions are welcome!

      Thanks,
      -John

      Comment


      • #4
        GetLocaleInfo() is what you want. That will give you the user or system default settings for both long date and short date.

        But if this is true...
        >The app must display certain dates in a multi-select listbox in the yyyy-mm-dd format.
        .. then I don't understand why you would care, since the format of your application is fixed.. unless.... you are looking to enhance your application by showing dates in the USER's preferred format.

        That, or perhaps the dates to be shown in your list control come from some kind of 'character string' source(?)

        If you keep all your dates internally as a SYSTEMTIME structure, you can adapt to anything, any time. It's what I do, even though I rarely have a need to deal with user settings for dates.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          OK, problem solved.

          In addition to double-checking that all controls were set to use the proper format, I checked the .inc file written by someone else that contained a call to:
          Code:
          GetDateFormat %LOCALE_USER_DEFAULT, dwFlags, st, BYCOPY lpFormat, szText, SIZEOF(szText)
          Through a series of nested calls, the caller was passing a value to lpFormat that forced the use of the LONGFORMAT, whereas I needed "dddd, yyyy-MM-dd"

          So I created a variable, passed my mask, and it works just fine now on the other machine.

          Took a LOT of reading and tracing and back and forth between machines, but not only is the problem resolved, but my confusion is gone, too. Well...till the next thing... :laugh:

          Thanks for the help, Michael, particularly the reminder that my code did not have to rely on the machine settings for date formats; re-thinking how my app is self-contained helped me get past my concerns about external influences.

          -John
          Last edited by John Montenigro; 12 Jul 2009, 08:31 PM.

          Comment

          Working...
          X