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

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.

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?

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/4293174/grab-all-wednesdays-in-a-given-month-in-php

Thanks for that… your google is much stronger than my google.

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

{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

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

[QUOTE=w33tbix;37277]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

{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

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

[/QUOTE]

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:



{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

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…

[QUOTE=rr;37283]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…[/QUOTE]

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

[QUOTE=aducom;37282]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:



{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[/QUOTE]

Parse error: syntax error, unexpected ‘$_SESSION’ (T_VARIABLE) in C:\Program Files (x86)\NetMake\v8\wwwroot\scriptcase\app\Racewish\Daysheet\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.

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 }

1103| new DateTime(“last day of $y-$m”)

your php statement is not terminated with a ;

[QUOTE=aducom;37298]1103| new DateTime(“last day of $y-$m”)

your php statement is not terminated with a ;[/QUOTE]

Parse error: syntax error, unexpected ‘;’ in C:\Program Files (x86)\NetMake\v8\wwwroot\scriptcase\app\Racewish\Daysheet\Daysheet_apl.php on line 1104

nolt getting any easier

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)



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

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

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


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

jsb

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.