Announcement

Collapse
No announcement yet.

Limiting date to a particular day of the week.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Limiting date to a particular day of the week.

    I'm fairly new to all this, was hopping SC would be a little more intuitive but am encountering issues that no matter how hard I look for answers nothing is close enough to giving me an answer, it's likely very basic but who knows.

    I have a field within a form "date field" which I'd like to display via a dropdown menu only wednesdays of each week, spacifically only the date of the next wednesday so filling in this form tomorrow "thursday for me would result in a selectable date of 10/06/2015 only, I'd like an option of having previous wednesday available but limited to only a couple.

    I was thinking of Jqurey or something but it's a little beyond my current capabilities but I'm learning slowly.

    I have another question but thought I'd see how I went with this one first, assuming I can figure this out in the next 15 days my boss has given approval to purchase, we are trying to develop a online timesheet for our employees where they can enter start and finish times and it calculates totals etc

    Thanks in advance

  • #2
    I don't know of any (jquery) object that can do this but I can be wrong. Retrieving dates depending on a workday is not that difficult as php has those routines build in. If you need to autoselect the next wednesday depending on an entered date then you can use an onscriptinit event to decide the date, determine next wednesday and present it in a regular edit field.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Ok thanks for the reply, next Question is how.

      Sorry like I said I'm fairly new to all this..... have you an example of the onscriptinit or the php routine?

      Comment


      • #4
        Create a field on your form (if not from the database, then you can create a custom one in the fieldlist left in the menu). Then click in the events on the onscriptinit link to create a php form. Apply your php here.

        To assign your formfield you need to put this between {} so the statement would be something like {mywednesday}= phpcode.

        If you google you'll find a lot of samples, so I put a link here. http://stackoverflow.com/questions/4...n-month-in-php
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Thanks for that..... your google is much stronger than my google.

          Comment


          • #6
            Sorry I just cant get this to work, it returns nothing but blank fields no matter what type of field textbox, dropdown etc

            I created in the onscriptinit
            Code:
            {Weekend}=  function getWednesdays($y, $m)
            {
                return new DatePeriod(
                    new DateTime("first wednesday of $y-$m"),
                    DateInterval::createFromDateString('next wednesday'),
                    new DateTime("last day of $y-$m")
                );
            }
            How would I use the usage part in a dropdown type form field so the user can select the date

            Code:
            foreach (getWednesdays(2010, 11) as $wednesday) {
                echo $wednesday->format("l, Y-m-d\n");
            }

            Comment


            • #7
              Originally posted by w33tbix View Post
              Sorry I just cant get this to work, it returns nothing but blank fields no matter what type of field textbox, dropdown etc

              I created in the onscriptinit
              Code:
              {Weekend}=  function getWednesdays($y, $m)
              {
                  return new DatePeriod(
                      new DateTime("first wednesday of $y-$m"),
                      DateInterval::createFromDateString('next wednesday'),
                      new DateTime("last day of $y-$m")
                  );
              }
              How would I use the usage part in a dropdown type form field so the user can select the date

              Code:
              foreach (getWednesdays(2010, 11) as $wednesday) {
                  echo $wednesday->format("l, Y-m-d\n");
              }
              No you can't do this, if you want to create a routine for this you need to apply a php method (under programming) or in a library. Try the simple way first:

              Code:
              {weekend} = new DatePeriod(
                      new DateTime("first wednesday of $y-$m"),
                      DateInterval::createFromDateString('next wednesday'),
                      new DateTime("last day of $y-$m")
              I think that if you need to make some standard routine of your own you should watch a few movies from the company website regarding php methods and / or libraries. It's explained pretty well, see e-learning section of scriptcase.net
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development
              www.scriptcase.eu / www.scriptcase.nl

              Comment


              • #8
                Eh why dont you simply use a good query to show all wednesdays?
                using date_sub you should be able to get this done. I assume you only want to show like say 100 coming wednesdays or all wednesdays for a year or so..

                This is for mysql so for another database you need another function of course.
                I would personally make a table with the numbers 0,7,14,21,28,.... in it for the number of weeks and simply find the first wednesday and cross this with this table...

                Comment


                • #9
                  Originally posted by rr View Post
                  Eh why dont you simply use a good query to show all wednesdays?
                  using date_sub you should be able to get this done. I assume you only want to show like say 100 coming wednesdays or all wednesdays for a year or so..

                  This is for mysql so for another database you need another function of course.
                  I would personally make a table with the numbers 0,7,14,21,28,.... in it for the number of weeks and simply find the first wednesday and cross this with this table...
                  I was thinking of doing this, I just cant get any other way to work without throwing errors..... I'm new I've said that and the tutorials arn't that usefull as they are too vague for someone who isn't a programmer, almost at the point of throwing in the towel

                  Comment


                  • #10
                    Originally posted by aducom View Post
                    No you can't do this, if you want to create a routine for this you need to apply a php method (under programming) or in a library. Try the simple way first:

                    Code:
                    {weekend} = new DatePeriod(
                            new DateTime("first wednesday of $y-$m"),
                            DateInterval::createFromDateString('next wednesday'),
                            new DateTime("last day of $y-$m")
                    I think that if you need to make some standard routine of your own you should watch a few movies from the company website regarding php methods and / or libraries. It's explained pretty well, see e-learning section of scriptcase.net
                    Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE) in C:\Program Files (x86)\NetMake\v8\wwwroot\scriptcase\app\Racewish\D aysheet\Daysheet_apl.php on line 1105

                    Comment


                    • #11
                      Originally posted by w33tbix View Post
                      Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE) in C:\Program Files (x86)\NetMake\v8\wwwroot\scriptcase\app\Racewish\D aysheet\Daysheet_apl.php on line 1105
                      Does your formfield exists and no spelling errors? Go to the application in scriptcase then go to edit -> view sourcecode. Then go to line 1105. You can see what sc has generated and useually you can figure out what's wrong. Remember that php is case sensitive so Wednesday is another variable than wednesday.
                      Albert Drent
                      aducom software netherlands
                      scriptcase partner, reseller, support and (turn-key) development
                      www.scriptcase.eu / www.scriptcase.nl

                      Comment


                      • #12
                        1099| $_SESSION['scriptcase']['Daysheet']['contr_erro'] = 'on';
                        1100| $weekend = new DatePeriod(
                        1101| new DateTime("first wednesday of $y-$m"),
                        1102| DateInterval::createFromDateString('next wednesday'),
                        1103| new DateTime("last day of $y-$m")
                        1104| $_SESSION['scriptcase']['Daysheet']['contr_erro'] = 'off';
                        1105| }
                        only thing on 1105 is }

                        Comment


                        • #13
                          Originally posted by w33tbix View Post
                          only thing on 1105 is }
                          1103| new DateTime("last day of $y-$m")

                          your php statement is not terminated with a ;
                          Albert Drent
                          aducom software netherlands
                          scriptcase partner, reseller, support and (turn-key) development
                          www.scriptcase.eu / www.scriptcase.nl

                          Comment


                          • #14
                            Originally posted by aducom View Post
                            1103| new DateTime("last day of $y-$m")

                            your php statement is not terminated with a ;
                            Parse error: syntax error, unexpected ';' in C:\Program Files (x86)\NetMake\v8\wwwroot\scriptcase\app\Racewish\D aysheet\Daysheet_apl.php on line 1104
                            nolt getting any easier

                            Comment


                            • #15
                              Ok, here is my take on it.
                              Since you want a drop down field for choosing the date, you might be better off
                              doing the calculation via MySQL. Otherwise you would have trouble to load it in a select field.

                              Copy/paste the statement in the box into a select field.

                              Change the table 'some_table' to any table of your db with at least 2 records in it. The table doesn't have to be related to the subject at all.
                              We just need it for a join, to get more than one date. Nothing will be changed in the table.

                              Here is what it does:
                              It takes the current date and calculates the date of the Wednesday of the week
                              DATE_ADD(CURDATE(), INTERVAL IF(WEEKDAY(CURDATE()) <> 2, 2 - WEEKDAY(CURDATE()), 0) day)

                              In a second step one ore two weeks are subtracted (depending if the Wednesday of the current week is in the future or in the past)
                              to get a starting point for the Wednesdays to list.
                              DATE_SUB(..., INTERVAL IF(WEEKDAY(CURDATE()) < 2, 2, 1) week)

                              Finally we add @i amount of weeks to the date calculated in the step before.
                              DATE_ADD( ..., INTERVAL @i week)

                              Code:
                              SELECT 
                                  wednesdays 
                              FROM
                                  (SELECT 
                                       DATE_ADD(DATE_SUB(DATE_ADD(CURDATE(), INTERVAL IF(WEEKDAY(CURDATE()) <> 2, 2 - WEEKDAY(CURDATE()), 0) day), INTERVAL IF(WEEKDAY(CURDATE()) < 2, 2, 1) week), 
                                       INTERVAL @i week) AS wednesdays,
                                       @i := @i + 1
                                  FROM some_table JOIN (SELECT @i := 1) c)p
                              Limit 2
                              I think this might be what you want, if not, have fun with it anyways.

                              jsb
                              Last edited by jsbinca; 06-05-2015, 01:31 PM.

                              Comment

                              Working...
                              X