Announcement

Collapse
No announcement yet.

Limiting date to a particular day of the week.

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

  • w33tbix
    started a topic Limiting date to a particular day of the week.

    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

  • w33tbix
    replied
    you know I had that exact same code in there, I figured the date_format thing out on my own but had it in the wrong spot and gave up till you replied, so thanks again, I'm getting there.

    Leave a comment:


  • jsbinca
    replied
    Regional settings do not apply to select fields. You have to format the field by yourself.
    Change your statement to:

    Code:
    SELECT 
        wednesdays, DATE_FORMAT(wednesdays,'%d/%m/%Y') 
    FROM
        ...
    jsb

    Leave a comment:


  • w33tbix
    replied
    Thankyou, that is exactly what I was looking for.... I have no idea how it works but it does work, I'll have a play with it and see if I can work out why it works.

    The only issue I'm having now is the date format is yyyy/mm/dd when it should be dd/mm/yyyy locales and any other setting I can think of has been set correctly, is this a database issue or is it something I can adjust somewhere?

    Thanks again to both of you for your help
    Last edited by w33tbix; 06-05-2015, 11:01 PM.

    Leave a comment:


  • jsbinca
    replied
    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.

    Leave a comment:


  • w33tbix
    replied
    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

    Leave a comment:


  • aducom
    replied
    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 ;

    Leave a comment:


  • w33tbix
    replied
    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 }

    Leave a comment:


  • aducom
    replied
    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.

    Leave a comment:


  • w33tbix
    replied
    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

    Leave a comment:


  • w33tbix
    replied
    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

    Leave a comment:


  • rr
    replied
    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...

    Leave a comment:


  • aducom
    replied
    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

    Leave a comment:


  • w33tbix
    replied
    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");
    }

    Leave a comment:


  • w33tbix
    replied
    Thanks for that..... your google is much stronger than my google.

    Leave a comment:

Working...
X