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 [modified]

date problem [modified]

Scheduled Pinned Locked Moved ASP.NET
helptutorial
15 Posts 7 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 dan sh

    What is the error it is throwing then?

    It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD

    V Offline
    V Offline
    venu656
    wrote on last edited by
    #5

    it was not reducing the day but it was not reducing the month

    1 Reply Last reply
    0
    • V venu656

      string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error

      modified on Monday, August 31, 2009 4:23 AM

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #6

      Actually the problem is DateTime parses according to the CultureSettings applied on the computer. If your global Date format is MM/dd/yyyy you cannot parse in dd/MM/yyyy. You can specify format while parse, using ParseExact function rather than Parse. :thumbsup:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      V 1 Reply Last reply
      0
      • A Abhishek Sur

        Actually the problem is DateTime parses according to the CultureSettings applied on the computer. If your global Date format is MM/dd/yyyy you cannot parse in dd/MM/yyyy. You can specify format while parse, using ParseExact function rather than Parse. :thumbsup:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        V Offline
        V Offline
        venu656
        wrote on last edited by
        #7

        No overload for method 'ParseExact' takes '1' arguments iam getting dis error

        A 1 Reply Last reply
        0
        • V venu656

          string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error

          modified on Monday, August 31, 2009 4:23 AM

          S Offline
          S Offline
          sashidhar
          wrote on last edited by
          #8

          try this code to decrease the date Label1.Text = DateTime.Now.AddDays(-1).ToString(); after u Get date time u can change as per your Requirement

          modified on Monday, August 31, 2009 5:32 AM

          V 1 Reply Last reply
          0
          • S sashidhar

            try this code to decrease the date Label1.Text = DateTime.Now.AddDays(-1).ToString(); after u Get date time u can change as per your Requirement

            modified on Monday, August 31, 2009 5:32 AM

            V Offline
            V Offline
            venu656
            wrote on last edited by
            #9

            iam not asking for lable ... iam getting a date in string format i want to decrease the particular date which is in string format

            S 1 Reply Last reply
            0
            • V venu656

              No overload for method 'ParseExact' takes '1' arguments iam getting dis error

              A Offline
              A Offline
              Abhishek Sur
              wrote on last edited by
              #10

              use this

              DateTime dt = DateTime.ParseExact("18/02/2001", "dd/MM/yyyy", new CultureInfo("en-US"));

              You will get what you want. :cool:

              Abhishek Sur


              My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

              **Don't forget to click "Good Answer" if you like to.

              1 Reply Last reply
              0
              • V venu656

                iam not asking for lable ... iam getting a date in string format i want to decrease the particular date which is in string format

                S Offline
                S Offline
                sashidhar
                wrote on last edited by
                #11

                Convert the string format date into Datetime format i.e. use the following code

                DateTime dt = DateTime.ParseExact("25/11/2009", "dd/MM/yyyy", new CultureInfo("en-US"));

                or u Can Use This

                string ssd = DateTime.Now.AddDays(-1).ToString();
                DateTime asd = Convert.ToDateTime(ssd);
                ssd = asd.AddDays(-1).ToString();

                if this is not Your Answer I am Sorry..!

                modified on Monday, August 31, 2009 6:07 AM

                1 Reply Last reply
                0
                • V venu656

                  string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error

                  modified on Monday, August 31, 2009 4:23 AM

                  G Offline
                  G Offline
                  Gaurav Dudeja India
                  wrote on last edited by
                  #12

                  you can do by this, just remove the opening and closing brace. string newdate =DateTime.Parse(todate).AddDays(-1).ToString("dd/MM/yyyy");

                  1 Reply Last reply
                  0
                  • V venu656

                    string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error

                    modified on Monday, August 31, 2009 4:23 AM

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #13

                    Hi , First parse string into date format and remember u should use yyyy/mm/dd format. datetime date = datetime.parse(date); date = date .AddDays(-1) Thanks, Amit Patel

                    S 1 Reply Last reply
                    0
                    • L Lost User

                      Hi , First parse string into date format and remember u should use yyyy/mm/dd format. datetime date = datetime.parse(date); date = date .AddDays(-1) Thanks, Amit Patel

                      S Offline
                      S Offline
                      Shuaib wasif khan
                      wrote on last edited by
                      #14

                      just get month year day through substring string year = txtdate.Text.Substring(6, 4); string month = txtdate.Text.Substring(3, 2); string day = txtdate.Text.Substring(0, 2); DateTime dt=DateTime.Parse(year+"/"+month+"/"+day); string date = dt .AddDays(-1);

                      1 Reply Last reply
                      0
                      • V venu656

                        string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error

                        modified on Monday, August 31, 2009 4:23 AM

                        S Offline
                        S Offline
                        Shuaib wasif khan
                        wrote on last edited by
                        #15

                        string year = txtdate.Text.Substring(6, 4); string month = txtdate.Text.Substring(3, 2); string day = txtdate.Text.Substring(0, 2); DateTime dt=DateTime.Parse(year+"/"+month+"/"+day); date = date .AddDays(-1) txtdate is the textbox for date input:rose:

                        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