Solved

Problems with Dates in UK format for a filter

Posted on 1998-09-21
2
167 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 84
sum13 challenge 24 146
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 546
Path of Workbook 3 87
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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