Link to home
Start Free TrialLog in
Avatar of AsifMughal
AsifMughal

asked on

Problems with Dates in UK format for a filter

Hello All

I am defining a filter for a recordset which brings back records between two given dates.  The code is as follows:


if (!m_strSearchDateTo.IsEmpty() && !m_strSearchDateFrom.IsEmpty()) {
            if (!pDoc->m_pPatientSet->m_strFilter.IsEmpty()) {
                  pDoc->m_pPatientSet->m_strFilter += " AND ";
            }
            pDoc->m_pPatientSet->m_strFilter += "Fare_DateFrom >= #" + DateFrom + "# AND " + "Fare_DateTo <= #" + DateTo + "#";
            
      }            
      }

This code only works if the date is in American Format mm/dd/yy and does not work for the date in English format dd/mm/yy.  I have checked my machine setting and they are set to the English date system.

I have tried using the format command to convert the English date to the American date so that it can be used by the query, using the following code:

CString Temp1;
Temp1.Format(m_strSearchDateFrom , "%m/%d/%y");


This has not worked, as the Filter reads the date in the English format instead of the American format. Is anyone aware how to convert a English format date to an American date format? I am using ODBC using the CRecordSet class.

Look forward to your reply.


Best Regards


Asif
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Answers2000
Answers2000

Oops labelled the variables wrong way round (swap day and month in both the Format lines to make the names match the field's purpose).

Having said that, the original code will work, it's just confusing the way I wrote it