Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 711
  • Last Modified:

Using COledateTime in a record set in lieu of CTime

'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
dooley090698
Asked:
dooley090698
  • 4
  • 4
  • 2
1 Solution
 
inprasCommented:
could U please explain what U mean Isolating time?
0
 
dooley090698Author Commented:
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
 
CriusCommented:
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
Technology Partners: 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!

 
inprasCommented:
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
 
dooley090698Author Commented:
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
 
CriusCommented:
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
 
dooley090698Author Commented:
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
 
CriusCommented:
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
 
dooley090698Author Commented:
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
 
CriusCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now