如何以6位數(shù)表示期次
在許多企業(yè)管理系統(tǒng)開發(fā)中,很多報表設(shè)計的數(shù)據(jù)提取方式都需要用到期次的概念。而使用6位數(shù)的期次來表示是一種常見的方法。具體地說,當(dāng)月1號(含1號)開始到當(dāng)月31號(含31號)為止算一個當(dāng)期次。為實現(xiàn)這個
在許多企業(yè)管理系統(tǒng)開發(fā)中,很多報表設(shè)計的數(shù)據(jù)提取方式都需要用到期次的概念。而使用6位數(shù)的期次來表示是一種常見的方法。具體地說,當(dāng)月1號(含1號)開始到當(dāng)月31號(含31號)為止算一個當(dāng)期次。
為實現(xiàn)這個功能,我們需要編寫一段代碼。其中,包括了上期的V_shangqi和本期的V_benqi的處理。如果當(dāng)前日期的月份是兩位數(shù),則直接將年份和月份拼接在一起即可。否則,還需要加上0作為占位符。以下是代碼示例:
if len(cstr(month(date))) 2 then
V_benqi cstr(year(date)) cstr(month(date))
else
V_benqi cstr(year(date)) "0" cstr(month(date))
end if
if len(cstr(month(date))) 1 then
if cint(month(date)) 1 then
V_shangqi cstr(int(year(date)) - 1) "12"
else
V_shangqi cstr(year(date)) "0" cstr(int(month(date))-1)
end if
else
if cint(month(date)) 10 then
V_shangqi cstr(year(date)) "09"
else
V_shangqi cstr(year(date)) cstr(int(month(date))-1)
end if
end if
根據(jù)客戶要求自定義范圍為一個期次
除了正常的1號到31號為一個當(dāng)期次的時間范圍外,還有可能根據(jù)客戶的要求進(jìn)行自定義。例如,某些公司規(guī)定到本月27號為止就是上個月的最后一天。此時,我們需要稍微改動一下代碼來實現(xiàn)自定義范圍為一個期次的功能。
假設(shè)以上月27日(含上月27號)開始到本月26號(含26號)為本期次的表示方法。以下是修改后的代碼示例:
if day(date) < 27 then
if len(cstr(month(date))) 2 then
V_benqi cstr(year(date)) cstr(month(date))
else
V_benqi cstr(year(date)) "0" cstr(month(date))
end if
else
if cint(month(date)) 9 or cint(month(date)) 10 or cint(month(date)) 11 then
V_benqi cstr(year(date)) cstr(int(month(date)) 1)
elseif cint(month(date)) 12 then
V_benqi cstr(int(year(date)) 1) "01"
else
V_benqi cstr(year(date)) "0" cstr(int(month(date)) 1)
end if
end if
if len(cstr(month(date))) 1 then
if cint(month(date)) 1 then
V_shangqi cstr(int(year(date))-1) "12"
else
V_shangqi cstr(year(date)) "0" cstr(int(month(date))-1)
end if
else
if cint(month(date)) 10 then
V_shangqi cstr(year(date)) "09"
else
V_shangqi cstr(year(date)) cstr(int(month(date))-1)
end if
end if
總結(jié)
以上是關(guān)于ASP項目筆記之:“6位數(shù)的期次表示”的內(nèi)容。在企業(yè)軟件開發(fā)中,期次的概念和應(yīng)用十分常見。針對不同的需求,我們可以采用不同的代碼來實現(xiàn)期次的表示和計算,從而滿足用戶的需求。