: Need Help with Now() and String comparison 
Author Message
 : Need Help with Now() and String comparison

Hello all,
   If I have a string " 08/19/98 11:01pm"

and compare it to Now() which returns something similar
"08/19/98 11:02pm" how can I figure out if that time has passed. I
tried using  

If  MyStr < Now() ....

but that seems to always be true. How can I get similar data types so
I can compare them?
Thanks,
  jeremy



Mon, 05 Feb 2001 03:00:00 GMT  
 : Need Help with Now() and String comparison
Try storing your date/times in variables declared as DATE.  Then you can do
a simple comparisons on them using the DateDiff() function which you will
find help for in the on line help.

For example;

Dim Time1    As Date
Dim Time2    As Date

    Time1 = Now
    '(do some work now)
    Time 2 = Now
    If (DateDiff("s" Time1, Time2)) Then
        Debug.Print "Timer Is Earlier"
    End If

Quote:

>Hello all,
>   If I have a string " 08/19/98 11:01pm"

>and compare it to Now() which returns something similar
>"08/19/98 11:02pm" how can I figure out if that time has passed. I
>tried using

>If  MyStr < Now() ....

>but that seems to always be true. How can I get similar data types so
>I can compare them?
>Thanks,
>  jeremy



Mon, 05 Feb 2001 03:00:00 GMT  
 : Need Help with Now() and String comparison
Hello,

there is a blank at the beginning of your comparison string, which makes
this string allways less then Now, cause Now gives allways a digit as a
first character.

Try to remove this first blank, your code should work then.

Bye,
Tanja.

themaker schrieb:

Quote:
> Hello all,
>    If I have a string " 08/19/98 11:01pm"

> and compare it to Now() which returns something similar
> "08/19/98 11:02pm" how can I figure out if that time has passed. I
> tried using

> If  MyStr < Now() ....

> but that seems to always be true. How can I get similar data types so
> I can compare them?
> Thanks,
>   jeremy



Mon, 05 Feb 2001 03:00:00 GMT  
 : Need Help with Now() and String comparison
For one thing, you will always get a different time every time you run the
NOW function.

But if you really want to;

If MyStr <> Now ....

But again, it will never equal since NOW now, is different than NOW a second
ago. :)

You might want to investigate the DateDiff functions to see if there is one
for TimeDiff or something that will suit what you are looking for.

Tim

Quote:

>Hello all,
>   If I have a string " 08/19/98 11:01pm"

>and compare it to Now() which returns something similar
>"08/19/98 11:02pm" how can I figure out if that time has passed. I
>tried using

>If  MyStr < Now() ....

>but that seems to always be true. How can I get similar data types so
>I can compare them?
>Thanks,
>  jeremy



Mon, 05 Feb 2001 03:00:00 GMT  
 : Need Help with Now() and String comparison

You might consider explicitly converting to date data type, then comparing
the dates:

Dim dtA as Date
Dim dtB as Date
Dim sTest as String

   sTest = "8/20/98 12:34"
   dtA = Now()    ' returns a Date type
   dtB = CDate(sTest)
   if dtA < dtB then
      blah blah
   else
      yack yack
   end if

VB can play all sorts of conversion games, but I prefer to keep things
explicit.

HTH.
--



Tue, 06 Feb 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. I need a FAST string comparison in VB

2. Need a FAST String Comparison!

3. Comparison strings with strings?

4. String comparison does not work

5. Null comparison with string

6. Single quote and dash act strangely in string comparison

7. string comparison statement

8. String extraction / comparison question

9. String.Intern Comparison Issues.

10. Looking for 'fuzzy' string comparison routine

11. SQL string comparison - dbgrid

12. Using a wildcard string comparison in a select case statement

 

 
Powered by phpBB® Forum Software