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;
////////////////
arvind_csAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
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...
0
arvind_csAuthor Commented:
In that case I get the following error:
'COleDateTime' : undeclared identifier
0
ZoppoCommented:
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
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

ZoppoCommented:
sorry, meant DATE instead of DATA both times               :)
0
arvind_csAuthor Commented:
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>

0
chensuCommented:
#include <afxwin.h>
....
#include <afxdisp.h>

#include "yourheader.h"
....
0
sumant032199Commented:
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.
0
ZoppoCommented:
Hi sumant, what has this to do with subject of the question (COleDateTime and DATE)???
0
arvind_csAuthor Commented:
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.
0
ZoppoCommented:
Now, does it still not work when you mix up chensu's and my suggestions?
0
arvind_csAuthor Commented:
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>
0
arvind_csAuthor Commented:
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>
) ?
0
chensuCommented:
Post your code around #include.
0
mikeblasCommented:
Are you using MFC or not, arvind_cs?

..B ekiM
0
chensuCommented:
If you are not using MFC, call the VarDateFromStr function.
0
arvind_csAuthor Commented:
To mikeblas: No MFC
0
chensuCommented:
OK, since you are not using MFC, you should not include afx*.h. You should use the VarDateFromStr function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikeblasCommented:
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
0
arvind_csAuthor Commented:
To MikeBlas: In that case why is it that when I use ::COleDateTime beginTime(a,b,...); I get 'COleDateTime not in glocal namespace' error?
0
mikeblasCommented:
> 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
0
arvind_csAuthor Commented:
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...
0
mikeblasCommented:
> 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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.