|
-
April 7th, 1999, 03:52 PM
#1
Compare Dates
Hi,
I retrieve a value from a Date field in my database. I need to compare this value with the current date. How can I do this without using MFC?
Thanks,
Therese
-
April 20th, 1999, 08:33 AM
#2
Re: Compare Dates
Let's say you've done something like this to retrieve your date value in your database :
COleVariant oleDateValue;
CDAORecordset daoRecordSet;
oleDateValue = daoRecordSet.GetFieldValue("DATE_COL");
To compare with the current date, you can do this :
COleDateTime oleCurrentDate;
oleCurrentDate = COleDateTime::GetCurrentTime();
if (oleCurrentDate == oleDateValue)
{
// Both dates are identical
}
else
{
// The dates are different
}
The COleDateTime class have some great methods to manipulate dates and time. Have a look at it in the help.
-
June 21st, 1999, 02:56 AM
#3
Re: Compare Dates
...but without using MFC you'd maybe want to access the underlying DATE data type? If you aren't using MFC at all you won't have COleVariant - will you have VARIANT though? You wont have the MFC DAO wrappers - will you have DAO though? Or are you using ADO? OLEDB? More of a question than an answer really, sorry - but clarify, what are you trying to do?
-
June 21st, 1999, 03:04 AM
#4
Re: Compare Dates
There is a Win32 structure SYSTEMTIME and many API's to get the time :
GetLocalTime(SYSTEMTIME);
GetSystemTime(SYSTEMTIME);
GetSystemTimeAdjustment(see help);
GetTimeZoneInformation(TIME_ZONE_INFORMATION);
...
You can look up the structures and methods in the MSDN, here's the SYSTEMTIME though:-
[ccode]
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
[ccode]
HTH
-
June 22nd, 1999, 02:18 PM
#5
Re: Compare Dates
I am using ADO for data access (via the #import). Right now I am accomplishing the comparison by parsing the date as if it were a string and comparing its "parts" to properties of a system time object.
This is pretty clumsy, so I am still open for suggestions.
Therese
-
November 19th, 2001, 08:06 AM
#6
Re: Compare Dates
Better way i have used to find the difference between two dates is to call DATEDIFF function from the backend
Syntax
DATEDIFF(datepart, startdate, enddate)
Returns the number of date and time boundaries crossed between two specified dates.
e.g.,
SELECT DATEDIFF(day, pubdate, getdate()) AS no_of_days
- getdate() will give u the current date
Everything that has a begining in time must have end in time.
-
November 19th, 2002, 12:23 PM
#7
How to get the difference between two variables of type DATE !!
hi,
I need to get the difference (in minute) between two variables of type DATE.
Example:
Code:
DATE d1; // 12/12/2002 12:10:20 AM
DATE d2; // 11/12/2002 11:10:20 AM
Thanks in advance.
Newbie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|