473,568 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COleDateTime: problem converting it to a DATE

We are experiencing a problem with COleDateTime while migrating our MFC&ATL project from VC++6.0 to VC++7.1 (Visual Studio .NET 2003).
COleDateTime has a DATE conversion operator that in 7.1 asserts when the date state is not valid. But we may need to pass NULL dates (read from a database) to our COM clients! - Yes, this problem doesn't occur in Release version, but we can't have a Debug version that asserts from time to time :)
A solution could be a small inline wrapper function that returns (DATE)0 when the state is null and else it calls the conversion operator, but it seems a bit "dirty".
Any suggestion?

Thank you very much
Paolo

Nov 17 '05 #1
5 8616
>We are experiencing a problem with COleDateTime while migrating our MFC&ATL project from VC++6.0 to VC++7.1 (Visual Studio .NET 2003).
COleDateTime has a DATE conversion operator that in 7.1 asserts when the date state is not valid. But we may need to pass NULL dates (read from a database) to our COM clients!


Paolo,

Which function in the MFC/ATL COleDateTime sources has this ASSERT?

Can you give a minimal example of how to reproduce this behaviour in a
manner that reproduces your more complex situation with the database
(but without the database of course).

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #2
"David Lowndes" wrote:
Which function in the MFC/ATL COleDateTime sources has this ASSERT?
Can you give a minimal example of how to reproduce this behaviour in a
manner that reproduces your more complex situation with the database
(but without the database of course).

***Server side***
When I read a date from the database using ADO, and that date is NULL (very likely, e.g. no starting time has been defined) I get a VT_NULL variant.
So I use the following code (where lpFieldName is a LPCTSTR, and pRecordset is an ADO Recordset (ordinary ADO, not .NET)

_variant_t vtFld;
COleDateTime time;
vtFld = pRecordset->Fields->GetItem(lpFiel dName)->Value;
switch(vtFld.vt )
{
case VT_DATE:
{
COleDateTime dt(vtFld);
time = dt;
}
break;
case VT_EMPTY:
case VT_NULL:
time.SetStatus( COleDateTime::n ull);
}

***Client side***
When I want to convert the COleDateTime to a DATE for a COM client, I write (of course, m_dtEstmStrtTm is a COleDateTime and dOutEstmStartTm is a DATE) :

dOutEstmStartTm = DATE(m_dtEstmSt rtTm);

or simply:

dOutEstmStartTm = m_dtEstmStrtTm; // the same!

The source code for COleDateTime in 6.0 reads:

_AFXDISP_INLINE COleDateTime::o perator DATE() const
{ return m_dt; }

But in 7.1 it reads:

ATLCOMTIME_INLI NE COleDateTime::o perator DATE() const throw()
{
ATLASSERT(GetSt atus() == valid);
return( m_dt );
}

that's not documented in MSDN 2003 (at least, I didn't find anything...) !

Shall I change the server side (i.e. avoid setting the status of COleDateTime to COleDateTime::n ull) or the client side (i.e. return zero when the status is COleDateTime::n ull) ?
Is zero the same as a "null" datetime? How can my clients tell a missing date from a "zero" date? I don't want them to display "midnight, 30 December 1899"!

Thank you very much
Paolo

Nov 17 '05 #3
>The source code for COleDateTime in 6.0 reads:

_AFXDISP_INLIN E COleDateTime::o perator DATE() const
{ return m_dt; }

But in 7.1 it reads:

ATLCOMTIME_INL INE COleDateTime::o perator DATE() const throw()
{
ATLASSERT(GetSt atus() == valid);
return( m_dt );
}
Paolo,

FWIW, it's currently the same in the VS2005 pre-release version.
Shall I change the server side (i.e. avoid setting the status of COleDateTime to COleDateTime::n ull) or the client side (i.e. return zero when the status is COleDateTime::n ull) ?
Is zero the same as a "null" datetime? How can my clients tell a missing date from a "zero" date? I don't want them to display "midnight, 30 December 1899"!


I'm really not sure what to recommend as your best course of action.
Zero isn't the same as a null datetime.

This isn't something I've come across (never doing anything with
databases). The best I can recommend is to check the status yourself
and code around the difference appropriately. If you feel that the
current behaviour is wrong by design, I suggest that you contact MS
product support (by telephone) and raise the issue with them. If you
make your case well enough, maybe it'll be changed for VS2005.

Dave
Nov 17 '05 #4
"David Lowndes" wrote:
ATLCOMTIME_INL INE COleDateTime::o perator DATE() const throw()
{
ATLASSERT(GetSt atus() == valid);
return( m_dt );
} FWIW, it's currently the same in the VS2005 pre-release version.
I'm really not sure what to recommend as your best course of action.
Zero isn't the same as a null datetime.


You're quite right. I did some digging, and discovered that with the previous version (compiled with VC++6.0), a "null" date was silently converted into a zero date. Clients (in our case, Visual Basic clients) can't tell zero from null, unless you use a VARIANT instead of a DATE. But I can't use a VARIANT, as a COM interface cannot be changed. I can see only one solution: explicitly use a zero date - and document that, in our application, a zero date means no date (Most of our clients assume that already). Can you figure a factory job that starts on January 1, 1900 ? :)
If you feel that the
current behaviour is wrong by design, I suggest that you contact MS
product support (by telephone) and raise the issue with them. If you
make your case well enough, maybe it'll be changed for VS2005.


No, that's OK, now I've got it: the assert is there to warn you: "hey, programmer, remember that DATE cannot represent null, unpredictable trouble may occur!!!".
But I think it should have been documented in MSDN -- It would have saved me from this headache!

Thank you very much for your reply
Paolo

Nov 17 '05 #5
I agree, I'll see what we can do for the 8.0 documentation to make this
clear.

Ronald Laeremans
Visual C++ team

"Paolo" <to************ *************** @web.tiscali.it/fanelia/noi.html>
wrote in message news:61******** *************** ***********@mic rosoft.com...
"David Lowndes" wrote:
>ATLCOMTIME_INL INE COleDateTime::o perator DATE() const throw()
>{
> ATLASSERT(GetSt atus() == valid);
> return( m_dt );
>}

FWIW, it's currently the same in the VS2005 pre-release version.
I'm really not sure what to recommend as your best course of action.
Zero isn't the same as a null datetime.


You're quite right. I did some digging, and discovered that with the
previous version (compiled with VC++6.0), a "null" date was silently
converted into a zero date. Clients (in our case, Visual Basic clients)
can't tell zero from null, unless you use a VARIANT instead of a DATE. But
I can't use a VARIANT, as a COM interface cannot be changed. I can see
only one solution: explicitly use a zero date - and document that, in our
application, a zero date means no date (Most of our clients assume that
already). Can you figure a factory job that starts on January 1, 1900 ? :)
If you feel that the
current behaviour is wrong by design, I suggest that you contact MS
product support (by telephone) and raise the issue with them. If you
make your case well enough, maybe it'll be changed for VS2005.


No, that's OK, now I've got it: the assert is there to warn you: "hey,
programmer, remember that DATE cannot represent null, unpredictable
trouble may occur!!!".
But I think it should have been documented in MSDN -- It would have saved
me from this headache!

Thank you very much for your reply
Paolo

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1388
by: Gary Smith | last post by:
I my SQL Datareader I am loading the date data into text box. Here is my code txtActOpenDate.Text = MyDataReader("ActOpenDt").ToString() txtActOpenDate.Text is displaying the date and time. How to display the date alone here. Thanks for your advice.
3
12419
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like Date in java? Thanks, Nate
9
12936
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i convert textbox data into Datatime formate it converted into MM/dd/yyyy formate, but i have a requirement in dd/MM/yyyy formate. please help me, i am...
6
34074
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
4
3333
by: krupalreddy | last post by:
i have a problem with date i have two dates. one is in Date type and the other one is in String type. i need to compare these two dates. for this i try to convert date which is in String type to Date type.is it possible? how?could you suggest the logic and methods?
3
7136
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying to autoformat the contents of text entries in a GUI. For numbers, I'm converting the text representation to the appropriate type (using atoi, atof,...
2
2667
by: jacc14 | last post by:
Hi Hope there is someone out there that can help. I am sure this is an easy one although not easy to explain. I have a form which produces a report using a query. On the form I have a start and end date which is in the query. So >=!!!. If I enter 2 dates it will produce the data I need. However the date field is a date and time...
4
4378
by: gubbachchi | last post by:
Hi, I have an issue regarding the php date format. I choose the date from date-picker which is in the format date('Y-m-d') i.e. 2008-09-12, then I will store this date in the variable $date_id and send this date to different php pages and I need to print the date from $date_id variable in the format date('d F Y') i.e. 12 september 2008. How...
4
1734
by: nikos | last post by:
Hi, I have a table with one of the columns configured to record dates as ('#', 'MM/DD/YYYY'). However, two entries in that column are of format YYYY and MM/YYYY. How can I change only those two entries preferably to Date but in formats above? i tried to do: "update table_name set column_name = to_date('2008', 'YYYY') where c_id = 12"
1
3650
by: =?Utf-8?B?bGF3ODc4Nw==?= | last post by:
i am looking for some MS Excel formula or MS Visal Basic Marco for converting Date to Lunar Date. tks
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.