Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共6 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:代码在一月份时出错?

1楼
mr725 发表于:2008/10/28 21:55:00
下面的代码当前时间是一月份时会出错,请前辈帮忙修改。

Dim d As Date = Date.Today
Dim Year As Integer = d.year
Dim Month As Integer = d.month
Dim StartDate As Date = New Date(Year,Month,1)
Dim EndDate As Date = New Date(Year,Month-1,Date.DaysInMonth(Year,Month-1))
OutPut.Show(startdate)
OutPut.Show(enddate)

图片点击可在新窗口打开查看此主题相关图片如下:我的代码 在1月份时出错?.jpg
图片点击可在新窗口打开查看
2楼
smileboy 发表于:2008/10/28 22:02:00
下载最新版本
3楼
贺老六 发表于:2008/10/28 22:07:00
应该是:

Dim EndDate As Date = New Date(Year,Month,Date.DaysInMonth(Year,Month))


4楼
mr725 发表于:2008/10/28 22:18:00
以下是引用贺老六在2008-10-28 22:07:00的发言:
应该是:

Dim EndDate As Date = New Date(Year,Month,Date.DaysInMonth(Year,Month))


哈哈~ 这个是本月的最后一天,我是想要上个月的最后一天!

还有,在命令窗口中,系统时间在2-12月之间都可以正常显示。

[此贴子已经被作者于2008-10-28 22:20:23编辑过]
5楼
lxl 发表于:2008/10/28 22:31:00
Dim d As Date = Date.Today
Dim Year As Integer = d.year
Dim Month As Integer = d.month
Dim StartDate As Date = New Date(Year,Month,1)
Dim EndDate As Date = StartDate.AddDays(-1)
OutPut.Show(startdate)
OutPut.Show(enddate)
6楼
mr725 发表于:2008/10/28 22:49:00
哈哈,对头,谢谢版主 lxl !

我也做出来了:
Dim d As Date = Date.Today
Dim Year As Integer = d.year
Dim Month As Integer = d.Month
Dim StartDate As Date = New Date(Year,Month,1)
Dim EndDate As Date
If Month <> 1 Then
   EndDate  = New Date(Year,Month-1,Date.DaysInMonth(Year,Month-1))
Else
   EndDate  = New Date(Year-1,12,Date.DaysInMonth(Year-1,12))
End If
OutPut.Show(startdate)
OutPut.Show(enddate)

但你的更简单!!
共6 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.