Checking dates using operators 
Author Message
 Checking dates using operators

Can someone tell me why the following line does not work.

FsDate is a variable with datetime info. i.e.  09/30/99 11:00:00 PM

If FsDate < Now Then
    etc..

Thanks
TomG



Fri, 15 Mar 2002 03:00:00 GMT  
 Checking dates using operators
Are you sure the variable FsDate contains both date AND time info?  Check
the value of that variable in Debug mode (type "?FsDate" in the Immediate
window) to be sure.

If the variable contains only the date, you should use something like this
to set its value:

    FsDate = DateValue("9/27/1999") + TimeValue("12:00:00 PM")

Then, when you compare it to Now(), it should return the correct result.  If
the variable already contains both date and time info, please post your code
snippet so we can help you out.

Regards,
Jake


Quote:
> Can someone tell me why the following line does not work.

> FsDate is a variable with datetime info. i.e.  09/30/99 11:00:00 PM

> If FsDate < Now Then
>     etc..

> Thanks
> TomG



Fri, 15 Mar 2002 03:00:00 GMT  
 Checking dates using operators
Here is the theory on ole dates (basicly what vb dates are...)

the date/time is a standard float.
the integer part is the number of the day since (I dunno), positive for
current
time, negative for before the switch day
the decimal part is the hour such that one entire day (24 hours) hold
between 0 and
0.9999... for instance, 12:00:00 is 0.5
if this helps (I play a lot with this, it's much easier to do the time
calculations like adding a second ( a + 1/86400 ) than using the stupid
dateadd
function (besides being much much faster)

Quote:

> Are you sure the variable FsDate contains both date AND time info?  Check
> the value of that variable in Debug mode (type "?FsDate" in the Immediate
> window) to be sure.

> If the variable contains only the date, you should use something like this
> to set its value:

>     FsDate = DateValue("9/27/1999") + TimeValue("12:00:00 PM")

> Then, when you compare it to Now(), it should return the correct result.  If
> the variable already contains both date and time info, please post your code
> snippet so we can help you out.

> Regards,
> Jake



> > Can someone tell me why the following line does not work.

> > FsDate is a variable with datetime info. i.e.  09/30/99 11:00:00 PM

> > If FsDate < Now Then
> >     etc..

> > Thanks
> > TomG



Fri, 15 Mar 2002 03:00:00 GMT  
 Checking dates using operators
Is FsDate declared as a Date? or as a String? To work properly, FsDate
*must* be declare as a Date. If not, then the comparison you are asking for
is done as a string comparison. As a string comparison, the zero in 09/30/99
11:00:00 PM is less than the 9 (first character) that Now produces.

Rick


Quote:
> Can someone tell me why the following line does not work.

> FsDate is a variable with datetime info. i.e.  09/30/99 11:00:00 PM

> If FsDate < Now Then
>     etc..

> Thanks
> TomG



Sat, 16 Mar 2002 03:00:00 GMT  
 Checking dates using operators
Tom

What type of variable is FsDate. Is it of type Date? If not then coerce it
to one:

If CDate(FsDate) < Now Then.....

Cheers
Dave Arkley


Quote:
> Can someone tell me why the following line does not work.

> FsDate is a variable with datetime info. i.e.  09/30/99 11:00:00 PM

> If FsDate < Now Then
>     etc..

> Thanks
> TomG



Sat, 16 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Finding date field using LIKE operator using ADO

2. How do I check date is a Valid Date

3. How to check a date between other dates

4. Type = Date..... checking txt inputs for dates

5. Using a dataset to check items in checked listbox

6. Select case using NOT operator

7. Using LIKE operator in ADO recordset

8. Type Mismatch Using the Like Operator

9. Logical operators using German settings

10. Exposing overloaded operator on C# class when used in VB.NET

11. Funtion definition in a class defining what to do if mathmatical operators are used

12. Using the "Like" operator

 

 
Powered by phpBB® Forum Software