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. C#
  4. need some DateTime help

need some DateTime help

Scheduled Pinned Locked Moved C#
regexquestionhelp
7 Posts 3 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.
  • J Offline
    J Offline
    Joshua Lunsford
    wrote on last edited by
    #1

    sorry, cant get my brain working this morning. the logical question I need my program to figure out is : The X day of every Y month(s) with a Startdate of Z and a (Enddate of W OR occur V times) this is my start: string matchpattern2 = "(0[1-9]|[12][0-9]|2[08])"; Regex re2 = new Regex(matchpattern2); if(re2.Match(monthly1TxtBox1.Text.ToString()).Success == true) { int intDays = 0; TimeSpan tsWeekly = endDateTime.Date.Subtract(startDateTime); intDays = tsWeekly.Days; DateTime[] datearray = new DateTime[intDays]; for(int x=0; x anyone experienced with doing something like this? -- modified at 9:06 Tuesday 20th December, 2005

    R J 2 Replies Last reply
    0
    • J Joshua Lunsford

      sorry, cant get my brain working this morning. the logical question I need my program to figure out is : The X day of every Y month(s) with a Startdate of Z and a (Enddate of W OR occur V times) this is my start: string matchpattern2 = "(0[1-9]|[12][0-9]|2[08])"; Regex re2 = new Regex(matchpattern2); if(re2.Match(monthly1TxtBox1.Text.ToString()).Success == true) { int intDays = 0; TimeSpan tsWeekly = endDateTime.Date.Subtract(startDateTime); intDays = tsWeekly.Days; DateTime[] datearray = new DateTime[intDays]; for(int x=0; x anyone experienced with doing something like this? -- modified at 9:06 Tuesday 20th December, 2005

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      What are you trying to do? Skimming over your code (use pre tags next time), I can't make out from your code what you're trying to accomplish.

      J 1 Reply Last reply
      0
      • J Joshua Lunsford

        sorry, cant get my brain working this morning. the logical question I need my program to figure out is : The X day of every Y month(s) with a Startdate of Z and a (Enddate of W OR occur V times) this is my start: string matchpattern2 = "(0[1-9]|[12][0-9]|2[08])"; Regex re2 = new Regex(matchpattern2); if(re2.Match(monthly1TxtBox1.Text.ToString()).Success == true) { int intDays = 0; TimeSpan tsWeekly = endDateTime.Date.Subtract(startDateTime); intDays = tsWeekly.Days; DateTime[] datearray = new DateTime[intDays]; for(int x=0; x anyone experienced with doing something like this? -- modified at 9:06 Tuesday 20th December, 2005

        R Offline
        R Offline
        Roy Heil
        wrote on last edited by
        #3

        Joshua Lunsford wrote:

        string matchpattern2 = "(0[1-9]|[12][0-9]|2[08])";

        I am not quite sure what your regular expression is supposed to match on. 0[1-9] matches 01 through 09. [12][0-9] matches 10 through 29. 2[08] matches 20 or 28. This is already covered by previous. Do you want it to be 3[0-8] Also, as it is, this RE will match number in a larger string. For instance, the following string will match on the 20: 34562055 If you only want two characters, try: (^0[1-9]|[12][0-9]|2[08]$) Roy.

        J 1 Reply Last reply
        0
        • R Roy Heil

          Joshua Lunsford wrote:

          string matchpattern2 = "(0[1-9]|[12][0-9]|2[08])";

          I am not quite sure what your regular expression is supposed to match on. 0[1-9] matches 01 through 09. [12][0-9] matches 10 through 29. 2[08] matches 20 or 28. This is already covered by previous. Do you want it to be 3[0-8] Also, as it is, this RE will match number in a larger string. For instance, the following string will match on the 20: 34562055 If you only want two characters, try: (^0[1-9]|[12][0-9]|2[08]$) Roy.

          J Offline
          J Offline
          Joshua Lunsford
          wrote on last edited by
          #4

          i want it to match on 1-28

          R 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            What are you trying to do? Skimming over your code (use pre tags next time), I can't make out from your code what you're trying to accomplish.

            J Offline
            J Offline
            Joshua Lunsford
            wrote on last edited by
            #5

            Judah Himango wrote:

            What are you trying to do?

            On the X day of every Y month(s) with a Startdate of Z and a (Enddate of W OR occur V times) i want to doSomeWork()

            Judah Himango wrote:

            I can't make out from your code what you're trying to accomplish.

            sorry, basically all i've done so far(in the code i posted) is make an array of DateTime's between the start and end date.

            J 1 Reply Last reply
            0
            • J Joshua Lunsford

              Judah Himango wrote:

              What are you trying to do?

              On the X day of every Y month(s) with a Startdate of Z and a (Enddate of W OR occur V times) i want to doSomeWork()

              Judah Himango wrote:

              I can't make out from your code what you're trying to accomplish.

              sorry, basically all i've done so far(in the code i posted) is make an array of DateTime's between the start and end date.

              J Offline
              J Offline
              Joshua Lunsford
              wrote on last edited by
              #6

              = startDateTime.AddDays(x); } Array.Sort(datearray); int loopcounter = 0; int intRecur = 0; if(occTxtBox.Text.Length > 0) intRecur = Int32.Parse(occTxtBox.Text.ToString()); int occurNum = 0; for(int x=0;x < intDays;x++) { if(intRecur == 0) { if(datearray[x].Day == dayOfMonth) { if(loopcounter == 0) { //DoWork loopcounter = loopcounter + iterativeMonths+1; } else if(datearray[x].Month == startDateTime.AddMonths(loopcounter).Month) { //DoWork loopcounter = loopcounter + iterativeMonths; } } } else { if(datearray[x].Day == dayOfMonth && occurNum < intRecur) { if(loopcounter == 0) { //DoWork loopcounter = loopcounter + iterativeMonths+1; occurNum++; } else if(datearray[x].Month == startDateTime.AddMonths(loopcounter).Month) { //DoWork loopcounter = loopcounter + iterativeMonths; occurNum++; } } } } msg.Text += "Task Added"; posAddEdit = 0; } else { msg.Text = "Please enter a day between 1 & 28"; } p.s. pre /pre always eats my for loops -- modified at 18:23 Wednesday 21st December, 2005

              1 Reply Last reply
              0
              • J Joshua Lunsford

                i want it to match on 1-28

                R Offline
                R Offline
                Roy Heil
                wrote on last edited by
                #7

                Joshua Lunsford wrote:

                i want it to match on 1-28

                Try this: (^0[1-9]|1[0-9]|2[0-8]$) PS. Sorry for taking so long. Holidays and all... Roy.

                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