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. Web Development
  3. ASP.NET
  4. Date Conversion Problem

Date Conversion Problem

Scheduled Pinned Locked Moved ASP.NET
5 Posts 5 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.
  • S Offline
    S Offline
    specialdreamsin
    wrote on last edited by
    #1

    Hi, I am using a Dataset, In which a Date field comes, I am assigning it to a String Variable. After than I am comparing it with Calender1.Selected Date. If CDate(Session("DispDt")) > CType(txtDespDate.Text, Date) Then lblMsg.Text = "Dispatch Date Must be Greater than " & MasterDispDt txtDespDate.Text = "" Exit Sub End If It is giving error as Conversion from string "31-01-2009" to type 'Date' is not valid. Please tell me What can be done. Ramesh Sambari

    M H Z A 4 Replies Last reply
    0
    • S specialdreamsin

      Hi, I am using a Dataset, In which a Date field comes, I am assigning it to a String Variable. After than I am comparing it with Calender1.Selected Date. If CDate(Session("DispDt")) > CType(txtDespDate.Text, Date) Then lblMsg.Text = "Dispatch Date Must be Greater than " & MasterDispDt txtDespDate.Text = "" Exit Sub End If It is giving error as Conversion from string "31-01-2009" to type 'Date' is not valid. Please tell me What can be done. Ramesh Sambari

      M Offline
      M Offline
      mr_muskurahat
      wrote on last edited by
      #2

      verify what is coming in your date variable from database?? it will give error only in the case when date string is not valid for example.. sometimes with day instead of 02 comes only 2 when we assign it to a string and datetime conversion fucntion gives error here..... try to give valid date to string.

      Government Dyal Singh College Lahore.

      1 Reply Last reply
      0
      • S specialdreamsin

        Hi, I am using a Dataset, In which a Date field comes, I am assigning it to a String Variable. After than I am comparing it with Calender1.Selected Date. If CDate(Session("DispDt")) > CType(txtDespDate.Text, Date) Then lblMsg.Text = "Dispatch Date Must be Greater than " & MasterDispDt txtDespDate.Text = "" Exit Sub End If It is giving error as Conversion from string "31-01-2009" to type 'Date' is not valid. Please tell me What can be done. Ramesh Sambari

        H Offline
        H Offline
        Hajab
        wrote on last edited by
        #3

        To convert a string to date, the date format should be MM/DD/YYYY OR MM/DD/YY. Check how you are retriving the date values from database.

        1 Reply Last reply
        0
        • S specialdreamsin

          Hi, I am using a Dataset, In which a Date field comes, I am assigning it to a String Variable. After than I am comparing it with Calender1.Selected Date. If CDate(Session("DispDt")) > CType(txtDespDate.Text, Date) Then lblMsg.Text = "Dispatch Date Must be Greater than " & MasterDispDt txtDespDate.Text = "" Exit Sub End If It is giving error as Conversion from string "31-01-2009" to type 'Date' is not valid. Please tell me What can be done. Ramesh Sambari

          Z Offline
          Z Offline
          Zia Ul Haq Soofi
          wrote on last edited by
          #4

          Conversion of date depends on your system's date and time setting. Probably computer assumes that 31 is month and 01 is day. Problem may be resolve by interchanging their positions like 01-31-2009, but it may appear when you deploy it to another system. To prevent this error, write your date like 31-Jan-2009, this method will never fails cause the use of month name abbreviation. This is my regular practice and I have got no error since I use it in this format. Try and best of luck.

          Be a part of solution, rather then be a part of problem

          1 Reply Last reply
          0
          • S specialdreamsin

            Hi, I am using a Dataset, In which a Date field comes, I am assigning it to a String Variable. After than I am comparing it with Calender1.Selected Date. If CDate(Session("DispDt")) > CType(txtDespDate.Text, Date) Then lblMsg.Text = "Dispatch Date Must be Greater than " & MasterDispDt txtDespDate.Text = "" Exit Sub End If It is giving error as Conversion from string "31-01-2009" to type 'Date' is not valid. Please tell me What can be done. Ramesh Sambari

            A Offline
            A Offline
            archit3000
            wrote on last edited by
            #5

            check the date format

            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