Home All Groups Group Topic Archive Search About

compare value from DTPicker and now()

Author
7 Jul 2005 10:20 AM
Henry
When i do the immediate enquiry:
Format(Now(), "YYYY/M/D") = 2005/7/7
dtpShipDate.Value = 2005/7/7

When I do the following comparison, the value is always false:
Format(Now(), "YYYY/M/D") = dtpShipDate.Value

Anybody knows why?

Author
7 Jul 2005 11:32 AM
Al Reid
"Henry" <henry@office> wrote in message news:O$3zC2tgFHA.3656@TK2MSFTNGP09.phx.gbl...
> When i do the immediate enquiry:
> Format(Now(), "YYYY/M/D") = 2005/7/7
> dtpShipDate.Value = 2005/7/7
>
> When I do the following comparison, the value is always false:
> Format(Now(), "YYYY/M/D") = dtpShipDate.Value
>
> Anybody knows why?
>
>

You are trying to compare a string to a Date data type, which is stored internally as a double.  VB is using Evil Type Conversion
(ETC) to try to figure out what you really want.  If you format the dtpShipDate.Value using the same format string as you did for
Now(), everything will work.  That is:

Format(Now(), "YYYY/M/D") = Format(dtpShipDate.Value, "YYYY/M/D")

Will return True, at least today.

--
Al Reid
Author
7 Jul 2005 1:13 PM
MikeD
Show quote Hide quote
"Al Reid" <arei***@reidDASHhome.com> wrote in message
news:udxN2eugFHA.1868@TK2MSFTNGP10.phx.gbl...
> "Henry" <henry@office> wrote in message
> news:O$3zC2tgFHA.3656@TK2MSFTNGP09.phx.gbl...
>> When i do the immediate enquiry:
>> Format(Now(), "YYYY/M/D") = 2005/7/7
>> dtpShipDate.Value = 2005/7/7
>>
>> When I do the following comparison, the value is always false:
>> Format(Now(), "YYYY/M/D") = dtpShipDate.Value
>>
>> Anybody knows why?
>>
>>
>
> You are trying to compare a string to a Date data type, which is stored
> internally as a double.  VB is using Evil Type Conversion
> (ETC) to try to figure out what you really want.  If you format the
> dtpShipDate.Value using the same format string as you did for
> Now(), everything will work.  That is:
>
> Format(Now(), "YYYY/M/D") = Format(dtpShipDate.Value, "YYYY/M/D")
>
> Will return True, at least today.


Or better yet, use the DateDiff function.

--
Mike
Microsoft MVP Visual Basic
Author
7 Jul 2005 8:48 PM
Saga
Try this:

if Date = dtpShipDate.Value then


Of course, if you only want to compare dates and not times,
leave the datetime picker's default format (ie it only accepts
dates) as is.

Good luck!
Saga
..
Show quoteHide quote
"Henry" <henry@office> wrote in message
news:O$3zC2tgFHA.3656@TK2MSFTNGP09.phx.gbl...
> When i do the immediate enquiry:
> Format(Now(), "YYYY/M/D") = 2005/7/7
> dtpShipDate.Value = 2005/7/7
>
> When I do the following comparison, the value is always false:
> Format(Now(), "YYYY/M/D") = dtpShipDate.Value
>
> Anybody knows why?
>