Link to home
Start Free TrialLog in
Avatar of arvind_cs
arvind_cs

asked on

Date

I want to convert a date (say "10:15PM March 19, 1999") and assign it to a DATE variable: what should I do? I tried the following without much luck
 (Compile error: 'COleDateTime' : is not a member of '`global namespace'').
////////////////
DATE *pVal;
::COleDateTime time4( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
*pVal = time4;
////////////////
Avatar of jkr
jkr
Flag of Germany image

You'll have to remove the scope resolution operator '::' from your code.

////////////////
DATE *pVal;
COleDateTime time4( 1999, 3, 19, 22, 15, 0 ); // *NO* '::' !
*pVal = time4;
////////////////

This should work...
Avatar of arvind_cs
arvind_cs

ASKER

In that case I get the following error:
'COleDateTime' : undeclared identifier
Hi arvind_cs,

To use COleDateTime you'll have to #include <afxdisp.h> ...

Further, why do you declare it as ::ColeDatTime instead of just COleDateTime ?
Next, you declare pVal as pointer to DATA, then you assign something to the DATE pointed to by pVal ... BUT, the pVal does not yet point to a valid DATA (access violation) ...

so, do something like this:

-------------------------------------------
#include <afxdisp.h>

....
DATE Val;
COleDateTime time4( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
Val = time4;
....
-------------------------------------------

hope that helps,

ZOPPO
sorry, meant DATE instead of DATA both times               :)
Thanks Zoppo. But I get this error when I include "afxdisp.h"
fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

#include <afxwin.h>
....
#include <afxdisp.h>

#include "yourheader.h"
....
You can use bitfield to store date and time in 2 different 16 bit numbers.

Bits
 15.....11 10........5 4.......0
   Hours     Minutes   Seconds/2
 
 15..........9 8.....5 4.......0
  Years since   Month     Day
     1980

comparing the date time is straight forward.
Hi sumant, what has this to do with subject of the question (COleDateTime and DATE)???
Thanks for the idea sumant, but as zoppo said, I am trying to use COleDateTime and DATE as I want to create a type library (with dual interface) accessible directly from VB.
Now, does it still not work when you mix up chensu's and my suggestions?
No it does not. I still get error during compilation.

fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
Zoppo, what you and chensu said matches with what I found out from MSDN but how do I get rid of this fatal error C1189 (WINDOWS.H already included. MFC apps must not #include <windows.h>
) ?
Post your code around #include.
Are you using MFC or not, arvind_cs?

..B ekiM
If you are not using MFC, call the VarDateFromStr function.
To mikeblas: No MFC
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jkr> You'll have to remove the scope resolution
 jkr> operator '::' from your code.  

Just for the record, that's not necessary.  MFC throws all its identifiers into the global namespace, so scoping to the global namespace with "::" is just fine. It's just that you have to be using MFC in the first place in order to get those symbols!

..B ekiM
To MikeBlas: In that case why is it that when I use ::COleDateTime beginTime(a,b,...); I get 'COleDateTime not in glocal namespace' error?
> In that case why is it that when I use  > ::COleDateTime beginTime(a,b,...); I get 'COleDateTime
 > not in glocal namespace' error?

Because you weren't using MFC. (Like I said.) COleDateTime is an MFC-provided class. If you haven't brought in the MFC headers, the class is not in your global namespace.

..B ekiM
To MikeBlas: Would I ever get the class name from the drop-down list in the editor immediately after I type :: if the class is never in my global namespace? I can access the class from the dropdown list. Now I am totally confused...
> Would I ever get the class name from the drop-down list in the
 > editor immediately after I type :: if the class is never in my  > global namespace?

Yes. Most of the dropdown list shown by statement completion is provided from a precompiled table the editor references. The rest of it is generated dynamically.

..B ekiM