SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    coneverting date

    the date in sql database is in yyyy-mm-dd format . i have a textbox where in date is eneterd in dd/mm/yyyy format i need to check the textbox date with the database date. how do i do it i tried converting the textbox date using format function but it didnot work

    If TXTDATE.Value <> "" Then
    Dim x = Format(TextBox1.Text, "mm/dd/yyyy")

    MsgBox(x)

    SWHERE = SWHERE & " AND datefield = '" & x & "' "

    End If



    this is the code i am having

  2. #2
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DateTime.TryParse
    http://msdn.microsoft.com/en-us/library/9h21f14e.aspx

    Code VBNET:
    Dim dt As DateTime
    DateTime.TryParse(TextBox1.Text, dt)

  3. #3
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with this i am getting true/false
    wht i want is the date enetred in textbox in dd/mm/yyyy format to be converted to yyyy/mm/dd or mm/dd/yyyy format

  4. #4
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, DateTime.TryParse will return true if the conversion was successfu and false otherwise. It's the DateTime variable 'dt' you want for the parsed date (if the parsing failed dt will be equal to DateTime.MinValue.) It's in the MSDN documentation.

    You can do something like this:
    Code VBNET:
    Dim dt As DateTime
    If DateTime.TryParse(TextBox1.Text, dt)
      MsgBox(dt.ToString)
    Else
      MsgBox("Invalid DateTime")
    End If

  5. #5
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks

    i got it
    this is wht i needed
    Convert.ToDateTime(TXT_DATE.Value).ToString("MM/dd/yyyy")


Bookmarks

Posting Permissions

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