2

I have dates stored in datetime in an MSSQL database. In my C++ application, these dates are pulled out of the database and stored in a CString.

I am trying to use COleDateTime's ParseDateTime() to display these dates in a nice format. However I found they are being displayed in american format (MM/DD/YYYY), and sorted as such. I would like them displayed in UK format (MM/DD/YYYY). I have attempted the code below to no difference:

codt.ParseDateTime(sqlresults.GetItem(_T("date"),l),0,MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK));

Thanks!

Raiden616
  • 1,545
  • 3
  • 18
  • 42
  • So does SUBLANG_ENGLISH_US solve the problem? If not it may be best to post the output of `sqlresults.GetItem(_T("date"),l)`. – mockinterface Feb 13 '14 at 10:42

1 Answers1

1

The ParseDateTime function is used to read the provided value – in your case you get it from the database and set the internal representation of the COleDateTime object.

You are not after this method but rather after the COleDateTime::Format method.

codt.ParseDateTime(
    sqlresults.GetItem(_T("date"),l),
    0,
    MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
CString dateAsUkString = codt.Format(_T("%d/%m/%Y"));
// display the dateAsUkString string in your view
mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • Sorry if I wasn't clear - the issue I am having is that when I use the Format method it displays the day as the month and the month as the day. The problem is that ParseDateTime, when it parses it, grabs the day value in the string and uses it as the internal month attribute and vice versa. – Raiden616 Feb 12 '14 at 10:35
  • @user1014679 In that case, have you tried switching to SUBLANG_ENGLISH_US ? – mockinterface Feb 12 '14 at 10:46