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 Problem

Date Problem

Scheduled Pinned Locked Moved ASP.NET
helpdatabasetutorial
11 Posts 4 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.
  • K Kissy16

    In sqlserver Database,datatype is smalldate/time and i tried following code Dim dtmDate As Date dtmDate = Date.Parse(TxtDat.Text) Response.Write("dtmdate") But it is giving String is not a valid datetype.How to format it examctle to isert into database. I need to isert only date not with the time. Help me out.please

    kissy

    T Offline
    T Offline
    thomas_joyee
    wrote on last edited by
    #2

    Try this. Date.Parse(TxtDat.Text).ToString("dd/MM/yyyy")

    Thomas

    K 1 Reply Last reply
    0
    • T thomas_joyee

      Try this. Date.Parse(TxtDat.Text).ToString("dd/MM/yyyy")

      Thomas

      K Offline
      K Offline
      Kissy16
      wrote on last edited by
      #3

      It is giving an errot that String was not recognised as valid Date. Give me solution,i Have used as below Dim dtmDate As DateTime dtmDate = Date.Parse(TxtDat.Text).ToString("mm-dd-yyyy") Response.Write("dtmdate") Here i am taking date from Calender. How to solve this,Thanks for ur answer

      kissy

      T 1 Reply Last reply
      0
      • K Kissy16

        It is giving an errot that String was not recognised as valid Date. Give me solution,i Have used as below Dim dtmDate As DateTime dtmDate = Date.Parse(TxtDat.Text).ToString("mm-dd-yyyy") Response.Write("dtmdate") Here i am taking date from Calender. How to solve this,Thanks for ur answer

        kissy

        T Offline
        T Offline
        thomas_joyee
        wrote on last edited by
        #4

        Your date format string is wrong. Use capital ‘M’ in the place of month. Like this "MM-dd-yyyy"

        Thomas

        K 1 Reply Last reply
        0
        • T thomas_joyee

          Your date format string is wrong. Use capital ‘M’ in the place of month. Like this "MM-dd-yyyy"

          Thomas

          K Offline
          K Offline
          Kissy16
          wrote on last edited by
          #5

          But eventhough i changed it is givig the same error.Where exactle i have to change the format,or else give me anothe idea

          kissy

          D 1 Reply Last reply
          0
          • K Kissy16

            But eventhough i changed it is givig the same error.Where exactle i have to change the format,or else give me anothe idea

            kissy

            D Offline
            D Offline
            dj rock
            wrote on last edited by
            #6

            what are you passing in your text box?? I mean what exactly you want to do?

            D 1 Reply Last reply
            0
            • D dj rock

              what are you passing in your text box?? I mean what exactly you want to do?

              D Offline
              D Offline
              dj rock
              wrote on last edited by
              #7

              You pass value in text box in mm/dd/yyyy format and you can display that value by following code stdate = DateTime.Parse(TextBox1.Text) Response.Write(stdate.ToString("dd MMM yyyy")) so if you pass 10/26/2006 it will display 26 Oct 2006 you can change format of date but you have to pass date in textbox in mm/dd/yyy format Try it :)

              K 1 Reply Last reply
              0
              • D dj rock

                You pass value in text box in mm/dd/yyyy format and you can display that value by following code stdate = DateTime.Parse(TextBox1.Text) Response.Write(stdate.ToString("dd MMM yyyy")) so if you pass 10/26/2006 it will display 26 Oct 2006 you can change format of date but you have to pass date in textbox in mm/dd/yyy format Try it :)

                K Offline
                K Offline
                Kissy16
                wrote on last edited by
                #8

                Dim stdate As DateTime = DateTime.Parse(TxtDat.Text) Dim strdate As DateTime = stdate.ToString("dd MM yyyy") and i am trying to isert this strdate valued into my smalldatetime datatype value in database.Then it is giving error that cast from 26 10 2006 to Date is not valid.Waht exactle i have to insert into my database for insertion of Date column.Like 26/10/2006

                kissy

                D C 2 Replies Last reply
                0
                • K Kissy16

                  Dim stdate As DateTime = DateTime.Parse(TxtDat.Text) Dim strdate As DateTime = stdate.ToString("dd MM yyyy") and i am trying to isert this strdate valued into my smalldatetime datatype value in database.Then it is giving error that cast from 26 10 2006 to Date is not valid.Waht exactle i have to insert into my database for insertion of Date column.Like 26/10/2006

                  kissy

                  D Offline
                  D Offline
                  dj rock
                  wrote on last edited by
                  #9

                  Dim strdate As DateTime = stdate.ToString("dd MM yyyy") this will never work kissy. as you are converting string into datetime so dont do that. instead you pass value when you are inserting it into database. and dont worry abot smalldatetime datatype it will take any value of date. so try to insert it as it is. and then let me know the changes Try it:)

                  K 1 Reply Last reply
                  0
                  • K Kissy16

                    Dim stdate As DateTime = DateTime.Parse(TxtDat.Text) Dim strdate As DateTime = stdate.ToString("dd MM yyyy") and i am trying to isert this strdate valued into my smalldatetime datatype value in database.Then it is giving error that cast from 26 10 2006 to Date is not valid.Waht exactle i have to insert into my database for insertion of Date column.Like 26/10/2006

                    kissy

                    C Offline
                    C Offline
                    cloudking11966
                    wrote on last edited by
                    #10

                    Hi Kissy, I was having the sme problem, before few months, I could get the right solution. The only thing you need to do is copy paste the below code in your Page_Load. CultureInfo ci = new CultureInfo("de-AT"); Thread.CurrentThread.CurrentCulture = ci; You will have to import System.Threading and System.Globalization in Import section This is nothing but setting up Dutche culture, so that your date format is fixed to dd/MM/yyyy format. While selecting from a calendar you may have to give SelectedDate.ToString.Replace(".","/") because it dispalys date in dd.MM.yyyy format. Cheers Sony Sebastian

                    1 Reply Last reply
                    0
                    • D dj rock

                      Dim strdate As DateTime = stdate.ToString("dd MM yyyy") this will never work kissy. as you are converting string into datetime so dont do that. instead you pass value when you are inserting it into database. and dont worry abot smalldatetime datatype it will take any value of date. so try to insert it as it is. and then let me know the changes Try it:)

                      K Offline
                      K Offline
                      Kissy16
                      wrote on last edited by
                      #11

                      Thank you so much for clearing my doubt. Here my mistake is in Calender i have used dd/mm/yyyy. and now it is working properly,Thank you once again

                      kissy

                      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