Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Date Conversion Problem

Date Conversion Problem

Scheduled Pinned Locked Moved Visual Basic
helpdatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danasegaranea
    wrote on last edited by
    #1

    Hi all, I hv coded a function to convert a string to a particular DateFormat. It works well good.But when I pass the dt as 25-12-2007 , I am getting the error as

    Message "The string was not recognized as a valid DateTime. There is a unknown word starting at index 0." String

    Function

    Public Shared Function DisplayFormatedDate(ByVal dt As String, ByVal strDateStringValue As String) As String
    Try
    Dim dttemp As String
    Dim strFormat As String = strDateStringValue.Trim
    strFormat = strFormat.Replace("mm", "MM")
    If Len(dt) > 0 Then
    'dttemp = Date.Parse(dt).ToString(strFormat)
    dttemp = Convert.ToDateTime(dt).Parse(strFormat).ToString
    End If
    Return dttemp
    Catch ex As Exception

        End Try
    End Function
    
    V 1 Reply Last reply
    0
    • D danasegaranea

      Hi all, I hv coded a function to convert a string to a particular DateFormat. It works well good.But when I pass the dt as 25-12-2007 , I am getting the error as

      Message "The string was not recognized as a valid DateTime. There is a unknown word starting at index 0." String

      Function

      Public Shared Function DisplayFormatedDate(ByVal dt As String, ByVal strDateStringValue As String) As String
      Try
      Dim dttemp As String
      Dim strFormat As String = strDateStringValue.Trim
      strFormat = strFormat.Replace("mm", "MM")
      If Len(dt) > 0 Then
      'dttemp = Date.Parse(dt).ToString(strFormat)
      dttemp = Convert.ToDateTime(dt).Parse(strFormat).ToString
      End If
      Return dttemp
      Catch ex As Exception

          End Try
      End Function
      
      V Offline
      V Offline
      VB Prog
      wrote on last edited by
      #2

      Replace dttemp = Convert.ToDateTime(dt).Parse(strFormat).ToString with dttemp = Convert.ToDateTime(dt).ToString(strFormat)

      VB Prog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups