Solved

Problems with Dates in UK format for a filter

Posted on 1998-09-21
2
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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