Convert and Store Textbox Date to Date Variable
-
I have textbox where I am showing the date and the format of this date is short date "01/01/2008".I have a variable called mDeliveryDate as date and I want to stroe the textbox date in Variable with the format "01-Jan-2008" for which I am using the following statement mDeliveryDate = Format(txtdate.text,"dd-MMM-yyyy") I am getting error something like conversion from string to date is invalid. Any idea how to fix this. Thanks in Advance Ejaz
-
I have textbox where I am showing the date and the format of this date is short date "01/01/2008".I have a variable called mDeliveryDate as date and I want to stroe the textbox date in Variable with the format "01-Jan-2008" for which I am using the following statement mDeliveryDate = Format(txtdate.text,"dd-MMM-yyyy") I am getting error something like conversion from string to date is invalid. Any idea how to fix this. Thanks in Advance Ejaz
Ejaz Defining mDeliveryDate as Date means it is stored in the system date format, not a string. The format is done later.
DateTime.TryParse(txtdate.text, mDeliveryDate ) Dim longDate As String = mDeliveryDate.ToString("dd-MMM-yyyy")
will give you "01-Jan-2008" in longDate. If it is an invalid date it will give you DateTime.MinValue (01-Jan-0001) Hope this helpsBob Ashfield Consultants Ltd
-
Ejaz Defining mDeliveryDate as Date means it is stored in the system date format, not a string. The format is done later.
DateTime.TryParse(txtdate.text, mDeliveryDate ) Dim longDate As String = mDeliveryDate.ToString("dd-MMM-yyyy")
will give you "01-Jan-2008" in longDate. If it is an invalid date it will give you DateTime.MinValue (01-Jan-0001) Hope this helpsBob Ashfield Consultants Ltd