Results 1 to 5 of 5

Thread: newB: can't format date UK to US [working]

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2003
    Location
    CA
    Posts
    16

    Question newB: can't format date UK to US [working]

    I am still new to VB and .NET
    I have searched this forum and tried lots of code and nothing works. Here is what I want to do and what I have:

    user enters date into textbox1.Text as 28/4/2003
    my code should format it to 4/28/2003 and test if isDate

    'Check if it is a valid date.
    Dim dtDate As Date = textbox1.Text
    Dim strDue As String
    strDue = Format(dtDate, "MM/dd/yyyy") 'this should format

    If IsDate(strDue) = False Then
    lblMessage.Text = "Please enter valid due date."
    lblMessage.Visible() = True
    txtDueDate.Text = ""
    Label1.Text = strDue
    Label1.Visible = True
    Exit Sub
    End If

    The code above returns an error:
    Cast from string "28/4/2003" to type 'Date' is not valid.

    If I make dtDate As String then
    strDue = Format(dtDate, "MM/dd/yyyy")
    returns MM/dd/yyyy in Label1.Text
    I used the Label1 to see what the return value of Format is.

    Please help me understand what is happening!
    Last edited by subegt; Apr 25th, 2003 at 12:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width