Re: [VB6 ] 如何轉成日期格式
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章