如何确定一个日期是否落在周末? [英] How to determine if a date falls on the weekend?

查看:132
本文介绍了如何确定一个日期是否落在周末?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

有一个工作日函数将Date作为参数返回日期(1,2,3等)



返回值为:

  vbSunday(1)
vbMonday(2)
vbTuesday(3)
vbWednesday(4)
vbThursday 5)
vbFriday(6)
vbSaturday(7)

假设周末是星期六和星期天,函数将如下所示:

 公共函数IsWeekend(InputDate As Date)As Boolean 
选择案例工作日(InputDate)
案例vbSaturday,vbSunday
IsWeekend = True
案例Else
IsWeekend = False
结束选择
结束函数


Given a date as input, how can I determine whether the day falls on a weekend?

解决方案

There is a Weekday function that takes a Date as an argument and returns the day (1, 2, 3, etc.)

The return values are:

vbSunday (1)  
vbMonday (2)  
vbTuesday (3)  
vbWednesday (4)  
vbThursday (5)  
vbFriday (6)  
vbSaturday (7)  

Assuming that weekends are Saturday and Sunday, the function would look like this:

Public Function IsWeekend(InputDate As Date) As Boolean
    Select Case Weekday(InputDate)
        Case vbSaturday, vbSunday
            IsWeekend = True
        Case Else
            IsWeekend = False
    End Select
End Function

这篇关于如何确定一个日期是否落在周末?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆