Home All Groups Group Topic Archive Search About
Author
27 Mar 2009 12:33 AM
Bee
I am trying to present the user with a date range, From ... To
I want to initially supply the earliest date and the latestest date.
This I believe to be according to the Help files

Dec 30, 1899 12:00:00 AM to Dec 31, 2099 12:00:00 AM
Let  sDate = Dec 30, 1899 12:00:00 AM

But I cannot do the following because CDate(sDate) returnes a Time 12:00 ???
I need to see that the user has input either a date only or date and time
but not time only.

Public Function IsDateAndOrTime(sDate As String) As eDateTimeEnum

    Dim dCheck As Date

    IsDateAndOrTime = eUnKnown
    If IsDate(sDate) Then
        dCheck = CDate(sDate)
        If dCheck > 0 And dCheck < 1 Then
            IsDateAndOrTime = eDateTimeEnum.eTimeOnly           ' it's just
a time
        ElseIf dCheck >= 1 And Fix(dCheck) = dCheck Then
            IsDateAndOrTime = eDateTimeEnum.eDateOnly           ' it's date
only
        ElseIf dCheck >= 1 Then
            IsDateAndOrTime = eDateTimeEnum.eDateAndTime    ' it's a date
and time
        End If
    End If

End Function 'IsDateAndOrTime

Suggestions

Author
27 Mar 2009 1:08 AM
Larry Serflaten
"Bee" <B**@discussions.microsoft.com> wrote

The logical equation  A Or (A And B) simplifies to just A.
That is your Date, Or Date And Time condition in equation form.
From that it can be seen that you could just check for a Date
value and if true, it passes your test.

With that in mind, it is a simple test:

Function HasDate(User As Date) As Boolean
  HasDate = (Abs(CDbl(User)) >= 1)
End Function


LFS
Author
27 Mar 2009 2:50 AM
Rick Rothstein
I think, since dates are stored as a Double, you can dispense with the CDbl
function call as the Abs function call will coerce the Date to its
underlying Double form in order to operate on it. While this is a type
coercion, I don't believe it can ever be an "evil" one given how your
function is using it.

Function HasDate(User As Date) As Boolean
  HasDate = (Abs(User) >= 1)
End Function

Where the use of outer parentheses is not required (except that some
consider it a more proper way to present the logical expression).

--
Rick (MVP - Excel)


Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OQlvfhnrJHA.3864@TK2MSFTNGP02.phx.gbl...
>
> "Bee" <B**@discussions.microsoft.com> wrote
>
> The logical equation  A Or (A And B) simplifies to just A.
> That is your Date, Or Date And Time condition in equation form.
> From that it can be seen that you could just check for a Date
> value and if true, it passes your test.
>
> With that in mind, it is a simple test:
>
> Function HasDate(User As Date) As Boolean
>  HasDate = (Abs(CDbl(User)) >= 1)
> End Function
>
>
> LFS
>
>
Author
27 Mar 2009 2:26 AM
Michael Cole
Bee  <B**@discussions.microsoft.com> wrote in message
<news:F5AB58F6-FC82-4E61-9A01-4519ABC10***@microsoft.com>

> I am trying to present the user with a date range, From ... To
> I want to initially supply the earliest date and the latestest date.
> This I believe to be according to the Help files
>
> Dec 30, 1899 12:00:00 AM to Dec 31, 2099 12:00:00 AM
> Let  sDate = Dec 30, 1899 12:00:00 AM

Minor point - Dates can be earlier than 30 Dec 1899.  It is just that that
date is date zero.  Earlier dates are stored as negatives.  Dates can also
be greater that 30 Dec 2009

You can go from 1-jan-100  to 30-dec-9999

--
Regards

Michael Cole