?
Solved

Using COledateTime in a record set in lieu of CTime

Posted on 2002-03-21
10
Medium Priority
?
693 Views
Last Modified: 2013-11-20
'm having a problem getting the date and time audit stamp into a new record of a data base.(using ODBC and CRecordsets).

The vendor has defined the fields as:
 FT_DATE  signed BCD('0YYYYMMDD') SIZE_OF_DATE (5 bytes)
 FT_TIME   signed BCD('0HHMMSSHH) SIZE_OF_TIME (5 bytes)
Time is a 24 hour clock: hours , minutes , seconds , hundreth of a second).

My recordset declares the two relevent variables as:
CTime     m_dtASDate; // FT_DATE  
CTime     m_tmASTime; // FT_TIME  

I need to stamp one filed with the date the other with the time.
The date isn't a probelm with:

CTime currd = CTime::GetCurrentTime();
int yr = currd.GetYear();
int mo = currd.GetMonth();
int day = currd.GetDay();
int hr = currd.GetHour();
int min = currd.GetMinute();
int sec = currd.GetSecond();
CTime m_dtASDate;(yr,mo,day,0,0,0);
This gives me a date only field.

However,I can;t seem to isolate the time only.Whenever I try to enter the time I awlays end up with a complete (date and time) entry.
How can I isolate the time only from this?
Any ideas?




0
Comment
Question by:dooley090698
[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
  • 4
  • 4
  • 2
10 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 6886305
could U please explain what U mean Isolating time?
0
 

Author Comment

by:dooley090698
ID: 6886362
K - in one field (CTime m_dtASDate; // FT_DATE) I want the date only in the format d/mo/yr

The other field (CTime m_tmASTime; // FT_TIME) I want the time only in the format Hr:Min:Sec

I can get the first field (date only) by simply setting the time to 0 but the second field has me befudled  as I always end up with the full (date n time).

Alos make note of the vendor's field definitions. This is the originating software. Mine is a third party add on,

0
 
LVL 3

Expert Comment

by:Crius
ID: 6886732
Are you looking for a CTimeSpan object?

CTime is made to handle both date and time. Why are you trying to handle date and time as separate objects? With both date and time, you can take only what you want, and create any format you like.

Assuming you want to populate those structure types with date time, one 'sneaky' way to do it is this:

FT_DATE WorkDate;
FT_TIME WorkTime;

CTime currd = CTime::GetCurrentTime();
short yr = currd.GetYear();
char mo = currd.GetMonth();
char day = currd.GetDay();
char hr = currd.GetHour();
char min = currd.GetMinute();
char sec = currd.GetSecond();

char *WorkPtr = (char *)WorkDate;
*WorkPtr++ = 0;
memcpy(WorkPtr, &yr, 2);   //You could do better than this, but may not be as readable.
WorkPtr+=2;
WorkPtr++ = mo;
WorkPtr++ = day;

WorkPtr = (char *)WorkTime;
WorkPtr++ = 0;
WorkPtr++ = hr;
WorkPtr++ = min;
WorkPtr++ = sec;
WorkPtr++ = (What?);

Done...?


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:inpras
ID: 6887231
You can also get the values like this
     CTime time1, time2;
     time2 = time1.GetCurrentTime();
     CString dateonly = time2.Format("%Y%m%w");
     AfxMessageBox(dateonly);
     CString timeonly = time2.Format("%H%M%S");
     AfxMessageBox(timeonly);
Regards
inpras
0
 

Author Comment

by:dooley090698
ID: 6888025
I need to use the COledateTime class in ODBC according to tech support as the date Dec 30,1899 will store only the time in the file then (that's what the originating software does).
All I have to do is fugure out how to use COleDateTime since the RFX_date takes a CTime member.
Any thoughts ??
0
 
LVL 3

Expert Comment

by:Crius
ID: 6888785
COleDateTime class has 4 member functions you could use:

SetDateTime Sets the value of this COleDateTime object to the specified date/time value.
SetDate Sets the value of this COleDateTime object to the specified date-only value.
SetTime Sets the value of this COleDateTime object to the specified time-only value.
Format Generates a formatted string representation of a COleDateTime object.

Hope this helps. (This is right out of the class member reference for COleDateTime)
0
 

Author Comment

by:dooley090698
ID: 6888910
Crius,
Not really. I can work  with the COledateTime BUT..how can I change my recordset to accept the COledateTime in the data exchange.
The variables are set up as a CTime like so:
CTime     m_dtASDate;
CTime     m_tmASTime;
// Data exchange
RFX_Date(pFX, _T("[dtASDate]"), m_dtASDate);
RFX_Date(pFX, _T("[tmASTime]"), m_tmASTime);

I want :
COledateTime  m_dtASDate;
COledateTime  m_tmASTime;

Simply changing to a RFX line to DFX as below
DFX_DateTime(pFX, _T("[dtASDate]"), m_dtASDate);
Doesn't work.

Is there a way to do it??
Txs

PS Some more info about the data base:
It's an Access data base but I can't use CDaoDatabase since  CDaoDatabase only allows creation of record sets from DB's with an mdb extension and this data base doesn't have an mdb extension.
Setting up the tables manually would be virtually impossible as there are so many of them.

Txs

0
 
LVL 3

Accepted Solution

by:
Crius earned 400 total points
ID: 6889021
Have you considered using a TIMESTAMP_STRUCT?:
void RFX_Date( CFieldExchange* pFX, const char* szName, TIMESTAMP_STRUCT& value );

typedef struct tagTIMESTAMP_STRUCT
    {
        SWORD year;
        UWORD month;
        UWORD day;
        UWORD hour;
        UWORD minute;
        UWORD second;
        UDWORD fraction;
    } TIMESTAMP_STRUCT;

I also stumbled upon this bug:

BUG: Time Value Converted to Datetime Using Access ODBC Driver

Q119487

In the MSDN library. It might be worth a read.
0
 

Author Comment

by:dooley090698
ID: 6889588
Oh god THANKS!!
You don;t know HOW long I've been trying to figure this out and using the TIMESTAMP_STRUCT solved my problem.
I couldn;t find this structure in the MSDN but no matter.. IT WORKS!!
Txs again!
0
 
LVL 3

Expert Comment

by:Crius
ID: 6889660
You're very welcome. :D I'm glad you finally got this problem fixed!

The reference I used in the MSDN can be found if you search for 'Q114961' titled: "RFX_Date() function for TIMESTAMP_STRUCT".

I used the October 2001 release of the MSDN.
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 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