473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Date/Time recognition

Hello,

VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into
a database I'm creating by verifying that an appropriate Date or Time value
has been entered. Using built-in VB functions/properties etc., I can't seem
to unambiguously confirm that an entry is a valid date or valid time value?
(I would like to try and do this without having to write some huge procedure
that processes an entry character by character, especialy with all the
permutations that are possible) 'IsDate' recognizes date or time as 'Date',
and I can't seem to interogate the variables to confirm it's one or the
other. I've been playing around with 'DateValue', 'DatePart', 'TimeValue',
'Year' functions etc............Ahhhhhh.

A suggestion in the right direction would be appreciated.

Thanks,

Gord
Jul 17 '05 #1
4 10983
> VB6 accepts Date and Time values as 'Date'. I'm trying to verify
entry into
a database I'm creating by verifying that an appropriate Date or Time value has been entered. Using built-in VB functions/properties etc., I can't seem to unambiguously confirm that an entry is a valid date or valid time value? (I would like to try and do this without having to write some huge procedure that processes an entry character by character, especialy with all the
permutations that are possible) 'IsDate' recognizes date or time as 'Date', and I can't seem to interogate the variables to confirm it's one or the other. I've been playing around with 'DateValue', 'DatePart', 'TimeValue', 'Year' functions etc............Ahhhhhh.

A suggestion in the right direction would be appreciated.


It is not completely clear to me whether you are trying to verify that
the entries are in the correct format for Dates and Times or simply if
the entry is a Time entry or a Date entry. I kind of think you are
looking for the latter. If so, you should be able to use these two
statements (don't change the colon or slash, using them makes the Format
statement return the value that is specified in the Regional settings,
whatever it is)...

DateSeparator = Format$(0, "/")
TimeSeparator = Format$(0, ":")

coupled with the InStr function to determine if the entry (assuming it
is properly formatted) is a Date entry, a Time entry or neither.

If InStr(YourEntry, DateSeparator) Then
MsgBox "Your entry is a Date."
ElseIf InStr(YourEntry, TimeSeparator) Then
MsgBox "Your entry is a Time."
Else
MsgBox "Your entry is neither!"
End If

Rick - MVP

Jul 17 '05 #2

"Gord" <x1******@telus.net> wrote in message
news:1cHwc.24878$jl6.7297@edtnps89...
Hello,

VB6 accepts Date and Time values as 'Date'. I'm trying to verify entry into a database I'm creating by verifying that an appropriate Date or Time value has been entered. Using built-in VB functions/properties etc., I can't seem to unambiguously confirm that an entry is a valid date or valid time value? (I would like to try and do this without having to write some huge procedure that processes an entry character by character, especialy with all the
permutations that are possible) 'IsDate' recognizes date or time as 'Date', and I can't seem to interogate the variables to confirm it's one or the
other. I've been playing around with 'DateValue', 'DatePart', 'TimeValue', 'Year' functions etc............Ahhhhhh.

A suggestion in the right direction would be appreciated.

Thanks,

Gord


You should be able to use the "IsDate" function to check both time and date.
For example:
? isdate("25:78")
False
? isdate("11:50am")
True
? isDate("4/5/04")
True
? isdate ("2/31/04")
False

I believe Rick addressed how to check the separator to see if it is a time
entry.
Jul 17 '05 #3
Rick,

Thanks. You're right, I am trying to determine if an entry is a date or
time. Formatting comes later. Your solution works, although it seems to be
necessary to copy the entry into a 'Date' variable in order for the 'InStr'
function to work. Even if 'IsDate' says a textbox entry is a valid date,
using that textbox (or a string variable) in the 'InStr' function won't
work. In your example 'YourEntry' needs to be a date variable.

I'm using the Microsoft reference library and Programmers Guide to (attempt)
to teach myself some basic programming. I'm wondering what the 'Format$(0,
"/")' or 'Format$(0, ":")' is all about? What expression does the '0'
represent?

Thanks

Gord
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:Ee********************@comcast.com...
VB6 accepts Date and Time values as 'Date'. I'm trying to verify

entry into
a database I'm creating by verifying that an appropriate Date or Time

value
has been entered. Using built-in VB functions/properties etc., I

can't seem
to unambiguously confirm that an entry is a valid date or valid time

value?
(I would like to try and do this without having to write some huge

procedure
that processes an entry character by character, especialy with all the
permutations that are possible) 'IsDate' recognizes date or time as

'Date',
and I can't seem to interogate the variables to confirm it's one or

the
other. I've been playing around with 'DateValue', 'DatePart',

'TimeValue',
'Year' functions etc............Ahhhhhh.

A suggestion in the right direction would be appreciated.


It is not completely clear to me whether you are trying to verify that
the entries are in the correct format for Dates and Times or simply if
the entry is a Time entry or a Date entry. I kind of think you are
looking for the latter. If so, you should be able to use these two
statements (don't change the colon or slash, using them makes the Format
statement return the value that is specified in the Regional settings,
whatever it is)...

DateSeparator = Format$(0, "/")
TimeSeparator = Format$(0, ":")

coupled with the InStr function to determine if the entry (assuming it
is properly formatted) is a Date entry, a Time entry or neither.

If InStr(YourEntry, DateSeparator) Then
MsgBox "Your entry is a Date."
ElseIf InStr(YourEntry, TimeSeparator) Then
MsgBox "Your entry is a Time."
Else
MsgBox "Your entry is neither!"
End If

Rick - MVP

Jul 17 '05 #4

"Gord" <x1******@telus.net> wrote in message
news:tZryc.28778$%i1.24850@edtnps89...
Rick,

Thanks. You're right, I am trying to determine if an entry is a date or time. Formatting comes later. Your solution works, although it seems to be necessary to copy the entry into a 'Date' variable in order for the 'InStr' function to work. Even if 'IsDate' says a textbox entry is a valid date, using that textbox (or a string variable) in the 'InStr' function won't work. In your example 'YourEntry' needs to be a date variable.


Like IsNumeric(X), which answers the question, "can I call CDbl(X)
without getting an error?", IsDate(X) answers the question "can I call
CDate(X) without getting an error?" Rick can post for you a fine example
of why IsNumeric is otherwise useless for checking for valid numeric
input.

I would do this something like:
Dim dtTest As Date

If IsDate(Text1.Text) Then
dtTest = CDate(Text1.Text)
If dtTest > 0 And dtTest < 1 Then
Debug.Print "its just a time"
ElseIf dtTest >= 1 And Fix(dtTest) = dtTest Then
Debug.Print "its just a date"
ElseIf dtTest >= 1 Then
Debug.Print "its a date and time"
End If
End If

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CJ Oxx | last post by:
I have a problem with browser charset recognition when using PHP 4.1.2 (this is the PHP version which our hosting company provides). For charset recognition, I use the following meta-tag: <meta...
0
by: avinash | last post by:
We apologize if this is a duplicate email. EIGHTEENTH INTERNATIONAL CONFERENCE ON SYSTEMS ENGINEERING (ICSEng05) LAS VEGAS, USA, AUGUST 16-18, 2005 (http://www.icseng.info) This series of...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
17
by: clintonG | last post by:
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central Standard Time) var today = new Date(); var GMTDate = today.toGMTString(); document.write("GMTDate: " + GMTDate); ...
4
by: Sandy Fleming | last post by:
What is the easiest way to force Access to read a date in a specific format? I have an application that imports a delimited text file with a date field in the format "mm/dd/yyyy". I've...
5
by: Rod | last post by:
About two weeks ago I had an accident and have broken my left elbow and left wrist. For doing things like Word or e-mail (I use Outlook for) I have been using Microsoft's speech recognition and...
1
by: Meena | last post by:
In our company we are trying to add speech recognition to our products. I downloaded the Speech Recognition engine. Now there is a component called Microsoft Direct Speech Recognition in VB.Net...
4
by: Ian Dickinson | last post by:
Hi My name is Ian Dickinson and I am a professional software developer working in the UK and reasonably familiar with Python. However a friend of mine who is a special educational needs teacher...
0
by: kalroche | last post by:
looking for expertise on a speech recognition project for thesis presentation My intention is to have speech recognition for product location for a grocery stores. What would be the best database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.