Solved

Using COledateTime in a record set in lieu of CTime

Posted on 2002-03-21
10
675 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 100 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 184
ffmpeg - "rtsp://...... Operation not permitted" 4 80
wordappend challenge 8 172
Sed question 2 83
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now