Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates

Status
Not open for further replies.

EscapeUK

Programmer
Jul 7, 2000
438
GB
I always seem to have problems with text and dates. Here is what I want to do.

I want a text box on a form and allow the user to enter a date in the format of dd/mm/yy.

I want to validate that so that it is entered in the correct format and to make sure it is not greater than today or less than 01/01/1995.

I then want to enter that date into a database but in the format of datetime.

The date must be in text format as some times the text "No date" is returned from the DB

So my questions are

How do I convert text into date
How do i convert a date into date time
 
1) Allowing a user to enter a date. One way to enforce data integrity is to use the Masked Edit Control. This control allows you to use input masks so that only the data you wish to have is entered in.

2) To validate a date, there is a function in VB called IsDate(). The parameter for IsDate is any expression, and it will evaluate True for a valid date, and False otherwise.

3) Converting text to dates: The function CDate() will convert any expression that has been successfully validated by IsDate to a Date data type.
 
Try using the date and time picker control.
It is located in one of the microsoft common controls. I use this control all the time!
Troy Williams B.Eng.
fenris@hotmail.com

 
in addition to fenris you might want to note that you need sp6 on NT4 to use the date and time picker known as dtpicker
or package it with your app.
The best way is just to set the format inform the use what to input then validate it with the isdate function. as for setting it to datetime all you can really do is add a time to it. If the time does not matter use all zeros would be my suggestion so you get it as of the first time of that day.
Chad
tinman@thelandofoz.org

Tinman,

Welcome to OZ.
 
I tried using masked edit boxes for the users to input dates and could not come up with a good way to totally validate for the correct format when they input. I then switched to the dtpicker and have since found out that you can not clear the dtpicker out since you can not have a null date. Well, does anyone have a work around for this? I do want to clear the dtpicker out in some instances such as the completition date the user may need to enter has not been reached as of yet. Does anyone know how to use the checkbox property on the dtpicker? Please help if you can.

Thanks,
Corinne
 
The best format I've seen is ISO 8601 (yyyy-mm-dd hh-mm-ss). No one *really* likes it, but it results in the most problem-free entry of dates. Europe is slowly moving towards it, Japan is already there, and the US is left behind as usual. No more confusion over July 1st vs. January 7th!

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top