Hi,
In vb.net, I want to let the user enter a date format in a textbox.
e.g : mm/dd/yyyy
dd/mm/yyyy
dd-mm-yyyy
Then, how can I check this is a valid date format and how can I build
an example so that it is displayed in another textbox ?
12/31/2005
Regards 17 2994
Hi,
Take a look at the datetime parse and parseexact methods http://msdn.microsoft.com/library/de...parsetopic.asp http://msdn.microsoft.com/library/de...exacttopic.asp
Ken
-------------------------
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,
In vb.net, I want to let the user enter a date format in a textbox.
e.g : mm/dd/yyyy
dd/mm/yyyy
dd-mm-yyyy
Then, how can I check this is a valid date format and how can I build
an example so that it is displayed in another textbox ?
12/31/2005
Regards
Thanks but it's not exactely what I want.
Again I want to check that the string entered by the user (e.g
DD/MM/yyyy) is a valid date format and then prove it by displaying an
example (14/12/2005)
Sam,
Normally should the IsDate function be enough
Cor
Hi,
You could use a regex to check that it is a valid date format or
use a try catch block
Regex
Dim rValid As New System.Text.RegularExpressions.Regex("(0[1-9]|1[012])[-
/.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d")
If rValid.IsMatch(TextBox1.Text) Then
Dim dt As DateTime
dt = DateTime.Parse(TextBox1.Text)
TextBox2.Text = dt.ToLongDateString
Else
MessageBox.Show("Invalid date format")
End If
Try catch block
Try
Dim dt As DateTime
dt = DateTime.Parse(TextBox1.Text)
TextBox2.Text = dt.ToLongDateString
Catch
MessageBox.Show("Invalid date format")
End Try
Ken
--------------------
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks but it's not exactely what I want.
Again I want to check that the string entered by the user (e.g
DD/MM/yyyy) is a valid date format and then prove it by displaying an
example (14/12/2005)
Ken You could use a regex to check that it is a valid date format or use a try catch block
In my opinion that is impossible the standard IsDate is very fine for that.
With using a regex you would allow in the first two 0-31 or test that
31-12 is allowed however
12-31 not
However the big problem is that you cannot do anything with that date. How
do you know what is
1-12-2005 without culture/language info info.
For you it is january 12 for me it is 1 december.
Cor
"Sam" <sa**************@voila.fr> schrieb: Again I want to check that the string entered by the user (e.g DD/MM/yyyy) is a valid date format and then prove it by displaying an example (14/12/2005)
I doubt that there is a way to check if a string is a valid date format,
because date format strings can contain arbitrary characters.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
I haven't tried IsDate yet, but I have tried Ken's idea with the try
catch block :
Try
Dim dt As DateTime
dt = DateTime.Parse("dddd - d - MMMM")
TextBox1.Text = dt.ToLongDateString
Catch
MessageBox.Show("Invalid date format")
End Try
However although dddd - d - MMMM is a valid format, it keeps raising an
exception :
The string was not recognized as a valid DateTime. There is a unknown
word starting at index 0.
Why that ?
Thx anyway for the replies guys
Cor,
I've tried IsDate :
?isdate("dd mmm yyyy")
False
?isdate("mm/dd/yyyy")
False
?isdate("dd/mm/yyyy")
False
?isdate("dd-mm-yyyy")
False
Can you explain that to me ? Those should be valid date format !
damn it.. I posted too quickly. Obviously IsDate expects a date, but
then it seems hard to convert the string format entered by the user to
a date... I'll try
I think I've got it :) Using these function :
Note that MyDate.ToString will get what the user entered in my textbox.
Dim MyDate As New DateTime(2005, 12, 31)
Dim MyString As String = MyDate.ToString("yyyy-MM-dd")
Dim res As Boolean = IsDate(MyString)
Thx
Sam,
As I wrote in this thread, the way dates are uses is depending on the
culture/language.
In Quibec it is the same as with us, however in Edmunton it is as in the
USA.
However I saw your latter message, therefore I assume you saw that already.
Cor
Cor,
What if I want to check for any kind of regional settings ?
For example "MM/dd/yyyy" is not valid on my machine but "dd/MM/yyyy" is
valid, and I want both of them to be valid, how ?
Thx
"Sam" <sa**************@voila.fr> schrieb: I've tried IsDate :
?isdate("dd mmm yyyy") False ?isdate("mm/dd/yyyy") False ?isdate("dd/mm/yyyy") False ?isdate("dd-mm-yyyy") False
Can you explain that to me ? Those should be valid date format !
'IsDate' is not intended for checking the validity of a date format string.
It's used to check the validity of a string representing a certain date.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
"Sam" <sa**************@voila.fr> schrieb: What if I want to check for any kind of regional settings ?
For example "MM/dd/yyyy" is not valid on my machine but "dd/MM/yyyy" is valid, and I want both of them to be valid, how ?
AFAIS every string is a valid date format, but an infinite number of date
strings won't contain the date in a readable form.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Sam,
Microsoft Net works only on computers which has there culture and language
setting, therefore should the right date be checked right on every computer.
In Paris using IsDate would a string 12/31/2005 be wrong and in New York
31/12/2005 if the user has not played with his culture settings.
(This is by the way not for webpages, in that you should have to find out
what culture the user is using).
I hope this helps,
Cor
Cor,
I understand this. My question was : is there a way to override this
behavious, that is prevent the application to check for regional
settings, OR check for every possible regional settings ?
Thx
Sam
Sam,
This should go automaticly. (Not for a webpage)
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gerrit Holl |
last post by:
Posted with permission from the author.
I have some comments on this PEP, see the (coming) followup to this message.
PEP: 321
Title: Date/Time Parsing and Formatting
Version: $Revision: 1.3 $...
|
by: praba kar |
last post by:
Dear All,
I have doubt regarding date string to time
conversion function. In Python I cannot find flexible
date string conversion function like php strtotime. I
try to use following type...
|
by: Simon Brooke |
last post by:
I'm investigating a bug a customer has reported in our database
abstraction layer, and it's making me very unhappy.
Brief summary:
I have a database abstraction layer which is intended to...
|
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...
|
by: Matteo |
last post by:
Hy everybody.
I'm not a html writer, but a sysadmin who's trying to help a user able
to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1,
Firefox 0.8+) due to a javascript date...
|
by: Martin Herrman |
last post by:
Dear scripters,
I am working on a HTML form in which a date must be entered of the form
'dd-mm-yyyy'. Now I'm looking for a script that, when the user switches to
another form field, changes...
|
by: Jim Davis |
last post by:
Before I reinvent the wheel I thought I'd ask: anybody got a code snippet
that will convert the common ISO8601 date formats to a JS date?
By "common" I mean at the least ones described in this...
|
by: Leo Muller |
last post by:
Hi,
Very often I have a problem with date formats.
There are cases I have to cast the date to text and from text to date on a
different server. However, sometimes the date formats on the servers...
|
by: Bob Achgill |
last post by:
I would like to use the timestamp on files to manage the
currency of support files for my VB windows application.
In this case I would only put the timestamp of the file
in the management database...
|
by: SOLVER |
last post by:
Hi,
I can't figure out why this is not working propelly:
date("d.m.Y",strtotime("05/03/2008 00:00:00")); result: 03.05.2008
date("d.m.Y",strtotime("18/05/2008 00:00:00")); result:...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |