Get System Date Format

Hi Experts,

Is there a way to get the setting for the short date format from Windows?

I need the dates displayed in my program customized to the region the program is being used in.

For example....mm/dd/yyyy, dd/mm/yy, dd/mm/yyyy, etc...

Or is there a way to send a date/string to Windows and have it return a formatted date?

Please no MFC.

Thanks!

-Me
CPOsoskyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
You can do that using either 'setlocale()' like

char* pszDateTime = setlocale(LC_TIME, NULL);

or 'GetLocaleInfo()'.

To have Windows format the output automatically using

TCHAR g_szBuf1[MAX_STR];
GetDateFormat(
  LOCALE_USER_DEFAULT,  // the locale for which the formatting is
                        //    being done
  DATE_LONGDATE,        // date format (long, short, ...)
  NULL,                 // the date to be formatted (here current
                        //    system date)
  NULL,                 // style of date format
  g_szBuf1,             // output buffer
  MAX_STR               // size of output buffer
);
MessageBox(NULL, g_szBuf1, TEXT("Long date format"), MB_OK);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.