作者fumizuki (蒙面加菲狮)
看板Visual_Basic
标题Re: [VB6 ] 如何转成日期格式
时间Sat Jun 17 21:42:30 2006
※ 引述《molucolin (molucolin)》之铭言:
: Dim Tim as string
: Tmp=GetChineseDate()
: Text1.text=Left(Tmp,3) '取年度
: =============================================
: select sum(field2) as TotalPiece from Table '从表单的栏位统计每月的
: where WestDate between BeginDate and EndDate '总件数
: =============================================
: Dim year as string
: Dim month as string
: year=Text1.text
: 而BeginDate 到 EndDate
: 分别为每年月初到月底
: 我想到的办法
: for i=1 to 12
: month = format(i,"00")
: BeginDate=CDate(year+"/"+month+"/01")
: EndDate=CDate(year+"/"+month+"/31"
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^这好像不符合逻辑
: 有些月份的最後一天不是31
EndDate = LastDayOfMonth(year, month)
Public Function LastDayOfMonth(Year As Integer, Month As Integer) As Date
Select Case Month
Case 1,3,5,7,8,10,12
MaxDay = 31
Case 4,6,9,11
MaxDay = 30
Case 2
If IsLeapYear(Year) Then MaxDay = 29 Else MaxDay = 28
End Select
LastDayOfMonth = CDate(Year & "/" & Month & "/" & MaxDay)
End Function
Public Function IsLeapYear(Year As Integer) As Boolean
If (Year Mod 400 = 0) Then
IsLeapYear = True
ElseIf (Year Mod 100 <> 0 And Year Mod 4 = 0) Then
IsLeapYear = True
End If
End Function
: 对了我这样转换日期格式没有问题吗
: 因为我看不到执行结果
: 所以无法判断是否这样行不通
: 对了闰年怎麽算啊就是看2月
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: 然後执行上面的SQL叙述
: 将rs.fields(TotalPiece)存到另一个表单
: 该月份的总件数
: rs2.Fields(Pieces)=rs.Fields(TotalPiece)
: rs2.MoveNext
: Next
: rs.close
: rs2.close
如果你是要查询整个月份的,不用这麽麻烦
select sum(field2) as TotalPiece from Table
where month(WestDate) = xxx
这样子写就好了...
--
▃▅▇▆▄ ▆▂▃ `
逝去感情如何能留住,半点痴情遗留殊不易,██▅▇▄▃ ▇▃▂" .
█████████▃i ▁▄▇
更多凄凄惨惨的遭遇…………██▆▃ █▅▆▃ˍ▄*
◢ ▂█▄▇▅▂▌.
我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.184.116.195