Foxtable(狐表)用户栏目专家坐堂 → 日期问题


  共有1785人关注过本帖树形打印复制链接

主题:日期问题

帅哥哟,离线,有人找我吗?
ifox2018
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:166 积分:1613 威望:0 精华:0 注册:2018/3/12 9:22:00
日期问题  发帖心情 Post By:2020/6/6 20:51:00 [显示全部帖子]

代码如下:
Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
Dim d As Date = Date.Today


'年
Dim y1 As New Date(y, 1, 1)
Dim y2 As New Date(y, 12, 31)
'月
Dim m1 As Date = New Date(d.Year,d.Month,1)
Dim m2 As Date = New Date(d.Year,d.Month,d.DaysInMonth(d.Year,d.Month))
'日
Dim d1 As New Date(y, m, 1)
Dim d2 As New Date(y, m, Date.DaysInMonth(y,m)) '获取该月的最后一天


'去年同期
Dim oldy As Date =  Date.today.AddYears(-1) 
Dim oldm1 As New Date(year(oldy), m, 1)
Dim oldm2 As New Date(year(oldy), m, Date.DaysInMonth(year(oldy),m)) '获取该月的最后一天
msgbox(oldy)
msgbox(oldm1)
msgbox(oldm2)


'上月度
Dim sy As  Date =  Date.today.Addmonths(-1) 
Dim sy1 As New Date(year(oldy),  month(sy), 1)
Dim sy2 As New Date(year(oldy),  month(sy), Date.DaysInMonth(y, month(sy))) '获取该月的最后一天
msgbox(sy)
msgbox(sy1)
msgbox(sy2)


测试了一下,发现个问题 :  当系统日期设置为今年3月时,报错   “年、月和日参数描述无法表示的 DateTime。”    其他月份都能执行。


 回到顶部