Click to See Complete Forum and Search --> : Compare Dates


Therese Lewis
April 7th, 1999, 03:52 PM
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
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.

d_wzrdv_z
June 21st, 1999, 02:56 AM
...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?

d_wzrdv_z
June 21st, 1999, 03:04 AM
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

Therese Lewis
June 22nd, 1999, 02:18 PM
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

KarthikeyanSP
November 19th, 2001, 07:06 AM
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.

bahruddina
November 19th, 2002, 11:23 AM
hi,

I need to get the difference (in minute) between two variables of type DATE.
Example:



DATE d1; // 12/12/2002 12:10:20 AM
DATE d2; // 11/12/2002 11:10:20 AM


Thanks in advance.
Newbie