473,789 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11000
> 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.2487 8$jl6.7297@edtn ps89...
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******** ************@co mcast.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.2877 8$%i1.24850@edt nps89...
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.Te xt) Then
dtTest = CDate(Text1.Tex t)
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
6199
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 http-equiv="Content-Type" content="text/html; charset=UTF-8"> Here is what I have tried so far: - Regular html page: charset is properly recognised - PHP page which just prints out the html: charset is not properly recognised (ISO charset is...
0
1405
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 International Conferences is jointly organized on a rotational basis among three institutions, University of Nevada, Las
4
5392
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 calculate days, months, and years. This is not for a college course. It's for my own personal genealogy website. I'm stumped about the code. I'm working on it but not making much progress. Is there any free code available anywhere? I know it...
17
2517
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); The code returns: Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
4
2643
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 written a function that converts it to a numeric date (integer).. and it's quite a long, convoluted function (it converts it to a medium date in the process). This may seem completely insane, but it was the only way I could think of to ensure that...
5
2222
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 that has been working fine. However as a professional programmer I need to be able to type. Right now I can't do that (until my arm heals). I've heard of a program by ScanSoft called Dragon NaturallySpeaking Professional. I called ScanSoft and...
1
9632
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 It would be really helpful if someone can get me the link where the help would be available for this component. In case someone know any other ways of adding speech recognition to the products, please send the link. It would be helpful too.
4
5873
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 was asking me if I could write some handwriting recognition software for her, which would allow here pupils to write their input directly on a graphics tablet and then have this input converted to a text sting for further processing. The handwriting...
0
1508
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 available which supports speech recognition. Any advise would be highly appreciated Thanks
0
9663
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9016
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.