【ASP】取得年月的最後一天

取得某年月的最後一天
' Returns the last day of the month. Takes into account leap years
' Usage: LastDay(Month, Year)


Function LastDay(MyMonth, MyYear)
 'MyYear用民國年算法
 'LastDay=day(dateserial(MyYear+1911,MyMonth+1,0))

 'MyYear用西元年算法
  LastDay=day(dateserial(MyYear,MyMonth+1,0))

 '以上紅色字...2擇一 
End Function

Ex2018年11月的最後一天
Response.Write     LastDay(11,2018)  =>30

Ex2018年2月的最後一天
Response.Write     LastDay(2,2018)   =>28

留言

這個網誌中的熱門文章

【ASP】日期轉換(西元<-->民國)

【VB】使用NPOI元件來匯出Excel--DataTableToExcel

【SQL】符號切割字串變成多欄