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
  1. Home
  2. General Programming
  3. Visual Basic
  4. Convert and Store Textbox Date to Date Variable

Convert and Store Textbox Date to Date Variable

Scheduled Pinned Locked Moved Visual Basic
helptutorial
3 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.
  • E Offline
    E Offline
    ejaz_pk
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • E ejaz_pk

      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

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      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 helps

      Bob Ashfield Consultants Ltd

      E 1 Reply Last reply
      0
      • A Ashfield

        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 helps

        Bob Ashfield Consultants Ltd

        E Offline
        E Offline
        ejaz_pk
        wrote on last edited by
        #3

        Thanks Bob I will try this.

        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