Re: [VB6 ] 如何轉成日期格式

看板Visual_Basic作者 (矇面加菲獅)時間19年前 (2006/06/17 21:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #14a__I8A (Visual_Basic)
討論串 (同標題文章)
文章代碼(AID): #14a__I8A (Visual_Basic)