Last post Mar 26, 2010 04:36 PM by atconway
Mar 23, 2010 10:43 PM|annir|LINK
Need you idea on this one.. I have a textbox then i need to convert the text that the user input in that text box into date..
For example the user input :1/2/2005 then i need to convert this into : 01/02/2005
anyone knows how to convert this.
I have this code but unfortunatley the conversation to the format that i need is wrong..
Mar 23, 2010 11:35 PM|Das.Sandeep|LINK
Dim podate As Date
podate = Format(CDate(txtdate.Text.ToString("00/00/2000")), "MM/dd/yy")
I have not tested but sure it will work
Mar 24, 2010 12:50 AM|annir|LINK
Thanks for the quick reply. I try your code but it gives me an error:
unable to cast object of type 'System.String' to type 'System.IFormatProvide'
Mar 25, 2010 06:42 PM|torren|LINK
To get the 0's in your output strings try:
Dim culture = CultureInfo.CurrentCulture
Date.ParseExact(txtdate.Text, "mm/dd/yyyy", culture).ToString("mm/dd/yyyy")
Mar 26, 2010 02:11 AM|annir|LINK
Thanks for the reply, I try to use this but it gives me an error at
Dim culture = CultureInfo.CurrentCulture saying that the CultureInfo is not yet declared.. Is culture mas be declared as date? string? or ??
Thanks and Regards.
Mar 26, 2010 02:44 AM|sathish_juk|LINK
podate = CDate(txtdate.Text.ToString("mm/dd/yyyy"))
Mar 26, 2010 04:36 PM|atconway|LINK
Here is the code you need:
'Create a variable to hold a date representing an improperly formatted date (for this example)
Dim MyDate1 As String = "1/2/2005"
Dim MyStringDateFormatted As String = Format(Date.Parse(MyDate1), "MM/dd/yyyy")
... the output is as follows:
...and for your example directly, try the following:
Dim MyStringDateFormatted As String = Format(Date.Parse(txtdate.Text.ToString), "MM/dd/yyyy")
Hope this helps!