Solved

Problems with Dates in UK format for a filter

Posted on 1998-09-21
2
163 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
ID: 1322396
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
ID: 1322397
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
sumNumber challenge 16 122
if loop in java 3 140
Remove Password Protection from pdf (with password) using an command line executable 5 50
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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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