1

So I have an input field where you select a date by clicking on a calendar and then that date is filled into a field.

<input type="text" name="date" value="" class="form-control datepicker" disabled="">

This field is filled when a visitor clicks on the date on a calendar, the date is then passed through to the field above using javascript.

$("td").click(function(){
   var day =  $(this).find(".day").html();
   $(".datepicker").val("<?php echo $this->uri->segment('3'); ?>/"+day+"/<?php echo $this->uri->segment('2'); ?>");
});

To create a value of something like this for example 07/14/2014

Then I have a drop down with a certain set of times. This is the Weekday Time Schedule:

<select name="time" class="form-control">
   <option value="4:30 PM">4:30 PM</option>
   <option value="5:30 PM">5:30 PM</option>
   <option value="6:30 PM">6:30 PM</option>
   <option value="7:30 PM">7:30 PM</option>
</select>

I have a different time frame set for weekends. But I currently have no way to distinguish between what days are weekdays and what days are weekends in the date field.

I am using codeigniter to generate the calendar and the form. So my dropdown looks like this:

<?php echo form_dropdown('time', $week_times, '', 'class="form-control"'); ?>

$week_times need to be converted into an if statement, something like the below so that I can provide two different sets of times based on what day of the week the day falls on for that month.

if(date == weekday){
   $times = $week_times;
}
elseif(date == weekend){
   $times = $week_end_times;
}

Obviosuly, that isn't a real if statement, but if I had that I wouldn't be asking the question How can I tell if a date field is a weekday or weekend and choose an array based off that information?

user3758114
  • 47
  • 2
  • 7
  • weekends are supposed to be `saturdays and sundays` right? just check the day of the date according to users input. [date](http://php.net/manual/en/function.date.php). then just have your preset time values (array) according to that day – user1978142 Jul 15 '14 at 03:26
  • Yes, weekends are `Saturday and Sunday` and weekdays are `Monday through Friday` `"just check what day it is today."` The date selected may not be todays date though. – user3758114 Jul 15 '14 at 03:27

1 Answers1

1

you could create a helper in CI so that it can be used commonly, and add :

function is_weekend($your_date) {
    $week_day = date('w', strtotime($your_date));
    //returns true if Sunday or Saturday else returns false
    return ($week_day == 0 || $week_day == 6);
}

and use it

if( is_weekend($date) ) {
    //its weekend do something
}
else {
    //its not weekend
}
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162