Solved

Using COledateTime in a record set in lieu of CTime

Posted on 2002-03-21
10
668 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

18 Experts available now in Live!

Get 1:1 Help Now