dqgo99177 2014-07-15 03:21
浏览 67
已采纳

确定日期是周末还是工作日[重复]

This question already has an answer here:

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?

</div>
  • 写回答

1条回答 默认 最新

  • duan19740319 2014-07-15 03:31
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名