date field: no time specified

Dear experts -
We have a form where people enter a date - and on occasion, a time as well.
If no time is entered, the system considers the hour to be 'zero' (I see this from the datepart function).
The question is: is there any way to determine whether or not a person has entered a time value (after all, it is possible that they manually entered 0 as an hour)?
The reason is that we use a time-conversion function in certain cases, but this is only relevant where the person has entered a time value.
Thanks!
terpsichoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
The quick check is:

If Int(datDateTime) = datDateTime Then
  ' No time part
End If

or:

If TimeValue(datDateTime) = #00:00# Then
  ' No time part
End If

/gustav
0
mbizupCommented:
If you are requiring input to be in a specific format such as yyyy-mm-dd hh:nn, you can test for the presence of a colon as a time delimiter:

If Instr(1,YourDateField, ":") > 0 then
      msgbox "Time was entered"
end if 

Open in new window



Or test for length:

If Len("" & YourDateField) > 10 then
      msgbox "Time was entered"
end if 

Open in new window


Code like this could go in the After Update event of your control or form.
0
Gustav BrockCIOCommented:
You should always handle date/time as date/time, not strings nor numbers.
Indeed string handling will fail in localized environments.

The nice test is:

If DateDiff("s", TimeValue(datDateTime), #00:00#) = 0 Then
  ' No time part
End If

/gustav
0
terpsichoreAuthor Commented:
question to gustav - but what if the time entered is 0:00:00 - I guess that's possible as a valid time entry?
I need to know whether the user has or has not entered ANY time value...
0
Gustav BrockCIOCommented:
That would count as no time part.
There is no difference between 2013-09-15 00.00 and 2013-09-15, only the format.

If you need an indication if no time is entered or 00.00 is entered, you will need a separate textbox to enter the time.

But again, you can't tell the difference between a date value and that value + #00:00#.

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.