Hi Every one
Need some help to Validate the Date i have in the Form.
ALso how to Convert the Date Data i read from table to yyyy/MMM/dd format.
Thanks
RSB 6 1959
You can validate a date using Regular Expressions. It is, by far the easiest
way with validation controls. To validate back end, you can also attempt to
cast into a DateTime structure and see if it blows up. While this may seem a
bit strange, the regex to correctly test for months of different lengths
would be rather large. The DateTime object will guarantee 2/29/2005 does not
slip in.
As far as date formatting, this is most easily changed using CultureInfo
objects and setting culture to a country that uses the date format you wish
to use. The other option is to rip the date apart, by parts, and reorder.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************
Think Outside the Box!
************************************************
"RSB" <rs*****@hotmail.com> wrote in message
news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd format.
Thanks
RSB
You can use the CompareValidator as well. Set the Operator property to
DataTypeCheck and set the Type property to Date.
-John Oakes
"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... You can validate a date using Regular Expressions. It is, by far the
easiest way with validation controls. To validate back end, you can also attempt
to cast into a DateTime structure and see if it blows up. While this may seem
a bit strange, the regex to correctly test for months of different lengths would be rather large. The DateTime object will guarantee 2/29/2005 does
not slip in.
As far as date formatting, this is most easily changed using CultureInfo objects and setting culture to a country that uses the date format you
wish to use. The other option is to rip the date apart, by parts, and reorder.
-- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************ Think Outside the Box! ************************************************ "RSB" <rs*****@hotmail.com> wrote in message news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd
format. Thanks
RSB
Here yer go ... as recommended by Cowboy, and cut'n'paste directly from an
app I'm writing.
The first test is for an ordinary date, explicitly coded to en-GB 'cos
browsers don't appear to return the right nationality and this is for UK.
The second test is because the users are occasionally lazy about 4 digit
years, the third test allows for year only entry - a requirement of the app
I'm writing, and the fourth test is just getting fancy; nobody will ever
type the word "today" into a text box. To parse other date formats simply
add more tests.
Cheers
Richard
_____________________________________________
Dr. Richard Petheram
AdlZ Ltd.
E-mail: richard_at_adlz.co.uk
_____________Web: www.adlz.co.uk ____________
[ CODE FOLLOWS ]
Public Shared Function ParseDate(ByVal pString As String, Optional ByRef
IsValid As Boolean = True) As DateTime
Dim lDTF As DateTimeFormatInfo =
CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat
Dim lResult As DateTime
Try
lResult = DateTime.Parse(pString, lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "dd/MM/yy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "yyyy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
If pString.Trim.ToLower = "today" Then
lResult = DateTime.Today.Date
IsValid = True
Return lResult
End If
IsValid = False
Return Nothing
End Function
[ END OF CODE ]
"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... You can validate a date using Regular Expressions. It is, by far the
easiest way with validation controls. To validate back end, you can also attempt
to cast into a DateTime structure and see if it blows up. While this may seem
a bit strange, the regex to correctly test for months of different lengths would be rather large. The DateTime object will guarantee 2/29/2005 does
not slip in.
As far as date formatting, this is most easily changed using CultureInfo objects and setting culture to a country that uses the date format you
wish to use. The other option is to rip the date apart, by parts, and reorder.
-- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************ Think Outside the Box! ************************************************ "RSB" <rs*****@hotmail.com> wrote in message news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd
format. Thanks
RSB
Hi John,
so can i also set the Date format for the CompareValidator???
Thanks
RSB
"John Oakes" <jo**@nospam.networkproductions.net> wrote in message
news:e%***************@TK2MSFTNGP10.phx.gbl...
You can use the CompareValidator as well. Set the Operator property to
DataTypeCheck and set the Type property to Date.
-John Oakes
"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... You can validate a date using Regular Expressions. It is, by far the
easiest way with validation controls. To validate back end, you can also attempt
to cast into a DateTime structure and see if it blows up. While this may seem
a bit strange, the regex to correctly test for months of different lengths would be rather large. The DateTime object will guarantee 2/29/2005 does
not slip in.
As far as date formatting, this is most easily changed using CultureInfo objects and setting culture to a country that uses the date format you
wish to use. The other option is to rip the date apart, by parts, and reorder.
-- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************ Think Outside the Box! ************************************************ "RSB" <rs*****@hotmail.com> wrote in message news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd
format. Thanks
RSB
Hi Richard,
thanks for the help.
So one question do you execute this code as a part of the Validation and
prompt an error message or it just check for the right error format...
"Richard Petheram" <rj*@adlz.co.uk> wrote in message
news:uL***************@newsfe1-gui.server.ntli.net...
Here yer go ... as recommended by Cowboy, and cut'n'paste directly from an
app I'm writing.
The first test is for an ordinary date, explicitly coded to en-GB 'cos
browsers don't appear to return the right nationality and this is for UK.
The second test is because the users are occasionally lazy about 4 digit
years, the third test allows for year only entry - a requirement of the app
I'm writing, and the fourth test is just getting fancy; nobody will ever
type the word "today" into a text box. To parse other date formats simply
add more tests.
Cheers
Richard
_____________________________________________
Dr. Richard Petheram
AdlZ Ltd.
E-mail: richard_at_adlz.co.uk
_____________Web: www.adlz.co.uk ____________
[ CODE FOLLOWS ]
Public Shared Function ParseDate(ByVal pString As String, Optional ByRef
IsValid As Boolean = True) As DateTime
Dim lDTF As DateTimeFormatInfo =
CultureInfo.CreateSpecificCulture("en-GB").DateTimeFormat
Dim lResult As DateTime
Try
lResult = DateTime.Parse(pString, lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "dd/MM/yy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
Try
lResult = DateTime.ParseExact(pString, "yyyy", lDTF).Date
IsValid = True
Return lResult
Catch ex As Exception
End Try
If pString.Trim.ToLower = "today" Then
lResult = DateTime.Today.Date
IsValid = True
Return lResult
End If
IsValid = False
Return Nothing
End Function
[ END OF CODE ]
"Cowboy" <No************@comcast.netNoSpamM> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... You can validate a date using Regular Expressions. It is, by far the
easiest way with validation controls. To validate back end, you can also attempt
to cast into a DateTime structure and see if it blows up. While this may seem
a bit strange, the regex to correctly test for months of different lengths would be rather large. The DateTime object will guarantee 2/29/2005 does
not slip in.
As far as date formatting, this is most easily changed using CultureInfo objects and setting culture to a country that uses the date format you
wish to use. The other option is to rip the date apart, by parts, and reorder.
-- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************ Think Outside the Box! ************************************************ "RSB" <rs*****@hotmail.com> wrote in message news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd
format. Thanks
RSB
I don't think so. It seems to understand most formats though. I wouldn't
consider it a full-proof method to validate a date, but it works pretty well
depending on what your need is.
-John
"RSB" <rs*****@hotmail.com> wrote in message
news:QV***************@news.cpqcorp.net... Hi John, so can i also set the Date format for the CompareValidator???
Thanks RSB "John Oakes" <jo**@nospam.networkproductions.net> wrote in message news:e%***************@TK2MSFTNGP10.phx.gbl... You can use the CompareValidator as well. Set the Operator property to DataTypeCheck and set the Type property to Date.
-John Oakes
"Cowboy" <No************@comcast.netNoSpamM> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... You can validate a date using Regular Expressions. It is, by far the easiest way with validation controls. To validate back end, you can also attempt to cast into a DateTime structure and see if it blows up. While this may
seem a bit strange, the regex to correctly test for months of different lengths would be rather large. The DateTime object will guarantee 2/29/2005 does not slip in.
As far as date formatting, this is most easily changed using CultureInfo objects and setting culture to a country that uses the date format you wish to use. The other option is to rip the date apart, by parts, and
reorder. -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
************************************************ Think Outside the Box! ************************************************ "RSB" <rs*****@hotmail.com> wrote in message news:YK****************@news.cpqcorp.net... Hi Every one
Need some help to Validate the Date i have in the Form. ALso how to Convert the Date Data i read from table to yyyy/MMM/dd format. Thanks
RSB
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Frank Rocco |
last post by:
Hello,
What is the best way to validate a textbox to see if it contains a valid
date or a valid time or both?
Thanks
Frank
|
by: Ali-R |
last post by:
Hi all,
I am getting a CSV file like this from our client:
"C1","2","12344","Mr","John","Chan","05/07/1976".........
I need to validate **each filed value** against a set of rules ,for...
|
by: James P. |
last post by:
Hello there,
In my asp.net page using VB, I have a date text field in mm/dd/yyyy
format. When a date is entered, I'd like to validate it to make sure
the date is greater than or equal to the...
|
by: yoshitha |
last post by:
hi
db : sql server 2000
lan : C#.net(ASp.Net)
in my database table there are 2 fileds of data type datatime.
in field 1 i'm storing date
in field 2 i'm storing time.
|
by: Michel Posseth [MCP] |
last post by:
I have a problem with the date time picker validate event wich i believe is
a bug
How to reproduce :
throw on a form a date time picker control and a textbox control
select the validating...
| |
by: pdesh3 |
last post by:
Hi,
I have a form in which 3 fileds are displayed on the top banner. They are DATE, NAME, LOCATION.
1. I want to make DATE filed dynamic where it whould read system date and display on...
|
by: samuelberthelot |
last post by:
Hello,
I would like to validate a date in a textbox on the onChange event.
The date must be in the format 01/01/2007
I would like to use a regular expression to validate it but I'm not
very...
|
by: shapper |
last post by:
Hello,
What is the Regex expression to validate a date time format as
follows:
dd-mm-yyyy hh:mm:ss
An example:
20-10-2008 10:32:45
|
by: shawnmiller77 |
last post by:
Need Help ASAP!
History: Installed new SBS 2003 server on Monday. Migrated IIS, website and current Access database over to new server. I did not develop the website or Access database. Former...
|
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...
|
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...
| |
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |