Solved

Problems with Dates in UK format for a filter

Posted on 1998-09-21
2
161 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:AsifMughal
  • 2
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
Comment Utility
Your Format call is incorrect.

Presumably you are trying to convert from m_strSearchDateFrom (UK format) to Temp1 (US format).

Temp1.Format( "%02d/%02d/%02d", day, month, year ) ;

where day, month and year are integers containing the appropriate parts of the date.

You can split m_strSearchDate using :

int month, day, year ;
sscanf( m_strSearchDateFrom, "%2d/%2d/%2d", &month, &day, &year ) ;



0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
conditional code and condition difference 9 65
Annoying "thing" blocks my view 4 49
Not needed 13 53
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now