CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880

    Question System time format (Answer found)

    Hi,

    do you know how I can get the system time format from Windows?

    My problem is that I have the date as a string, under a format I know about. I want to create a csv file to be able to open it in Excel. Excel use the system format to look if a string is a date or not.

    The problem will mainly appear for month/day. Usually, english format will be: "10/22/2002" while some other formats will be "22/10/2002".

    I need to know how to format the string in order to have excel recognise the string as a date, and not as a simple string. This is a window setting as you can change it in the control panel, so there must be some API function to look for it, but I don't know which...

    Any idea?
    Last edited by Elrond; October 22nd, 2002 at 10:55 AM.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  2. #2
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688
    take a look at setlocale()

    may be could help you.

  3. #3
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880

    Thumbs up Answer found

    Thanks.

    What I was looking for is the format item %c.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  4. #4
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    If the data is for a cell then it is possible to set the cell format. That way Excel is much more likely to process the data as a date.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  5. #5
    Join Date
    Sep 2002
    Posts
    77
    ...This is a window setting as you can change it in the control panel, so there must be some API function to look for it, but I don't know which...
    The Windows SDK function to query locale settings is GetLocaleInfo.

  6. #6
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880
    Originally posted by Sam Hobbs
    If the data is for a cell then it is possible to set the cell format. That way Excel is much more likely to process the data as a date.
    That's to write in a CSV format file, so it's not possible to set a cell format. On the other hand, even if you set the cell format as a date, if the string does not have the date and day in the correct position, at best it is just recognised as a string (if the day is more than 12), or even worse, it will invert month and day!!!!

    So I think the best is to use the proper format for the string in the first place.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

  7. #7
    Join Date
    Oct 2001
    Location
    Dublin, Eire
    Posts
    880
    Originally posted by alpha137
    The Windows SDK function to query locale settings is GetLocaleInfo.
    Thanks.

    As I'm just interested in the date/time format the %c format item does it much more easily (and probably quickly) for me.
    Elrond
    A chess genius is a human being who focuses vast, little-understood mental gifts and labors on an ultimately trivial human enterprise.
    -- George Steiner

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured