Groups | Blog | Home
all groups > asp.net > april 2006 >

asp.net : Get date from textbox


q
4/9/2006 8:48:12 PM
You could just use this...


string dateString = "01/02/1980";
DateTime date;
if (DateTime.TryParse(dateString, out date)) {
string month = date.Month;
string year = date.Year;
string day = date.Day;
}
else {
// Bad...
}
Dave
4/9/2006 11:50:23 PM
Hi,
I have a textbox that the user inserts the date of birth in the format
dd/mm/yyyy, I'm validating it with regex

to set the value to a Date variable, I have

dBithDay = CDate(txtBDate.txt)

but if the user enters 01/02/1980, the month of the date variable is 01
instead of 02.

should I use substring??

Thanks!

Bruno Piovan
4/10/2006 11:55:38 AM
You can do this way...

Dim dateString As String = "01/02/1980"
Dim dtfi As New System.Globalization.DateTimeFormatInfo
dtfi.ShortDatePattern = "dd/MM/yyyy"
Dim d As Date = Date.Parse(dateString, dtfi)

you can create an object of type CultureInfo and use it instead of
DateTimeFormatInfo

Bruno

[quoted text, click to view]

AddThis Social Bookmark Button