Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to compare date with character string

2 views
Skip to first unread message

Mac

unread,
Oct 5, 2005, 6:52:46 PM10/5/05
to

I have 2 columns:

1. pdate it is a datetime format 06/29/2005 11:00:00 AM


2. adate just a date 06/29/2005


I am trying to test this way but it does not work:

If pdate = adate + ' 11:00:00 AM' then
msgbox 'testing'
end if

By the way, the database is is SQL2K.

THANKS

Bob Butler

unread,
Oct 5, 2005, 7:04:39 PM10/5/05
to
"Mac" <m...@hotmail.com> wrote in message
news:2PY0f.4815$Ll2.1722@trnddc04

are the pdate and adate columns both defined as date/time in the database?
If so then try
if dateserial(year(pdate),month(pdate),day(pdate))=adate then

If they are text then you can use the Mid$ and CInt functions to get the
arguments for DateSerial to build dates.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Michael Cole

unread,
Oct 6, 2005, 8:01:08 PM10/6/05
to
Mac wrote:
> I have 2 columns:
>
> 1. pdate it is a datetime format 06/29/2005 11:00:00 AM
>
>
> 2. adate just a date 06/29/2005
>
>
> I am trying to test this way but it does not work:
>
> If pdate = adate + ' 11:00:00 AM' then
> msgbox 'testing'
> end if

Convert them both to Longs and then check the values.

--
Regards,

Michael Cole


Someone

unread,
Oct 6, 2005, 8:54:29 PM10/6/05
to
Use:

If DateValue(pdate) = DateValue(adate) Then

See also DateAdd and DateDiff in the help file, because you probably are
going to need them.

> Convert them both to Longs and then check the values.

Since Dates are represented internally as Double, with the integer part
representing whole days, and the fraction represents the fraction of the
day, the OP would have a problem if he or she used CLng(). CLng() rounds up
a fraction to the next whole number, i.e., CLng(1.5) = 2. "0.5" is a
representation of 12:00 PM(Midday). If the OP used Int() instead, then there
is no problem. I think you already know this, but a beginner could
misunderstand your answer.

"Michael Cole" <no...@hansen.com> wrote in message
news:uyLZ0Ity...@TK2MSFTNGP09.phx.gbl...

0 new messages