2つの日付の差を計算し、すべての月が30日であることを考慮して、差に応じて2年、5か月、または3か月、または2日に変換したい...
例えば;
開始および含む:2009年3月12日終了するが含まない:2011年11月26日
出力は、終了日を除いて2年、8か月、14日である必要があります。
もう一つの例;
開始:2010年1月26日終了:2010年2月15日
出力:開始日から終了日までの20日。ただし、終了日は含まれません。
Datediffを使用して、差を月、日、または時間として計算できますが、問題は、それを年、月、および日付に変換する方法です。2か月の間に何日あるかわからないので実際にはかなり複雑です(30、31、おそらく28日)
このクラシックASPコードを使用して違いを変換しますが、多くの欠点があります。
Function Convert_Date_to_Text(tarih1,tarih2,useDates)
if (tarih1<>"" AND tarih2<>"") then
if Tarih_Araligi_Belirle(tarih1,tarih2,"day")>0 then
Date1_Year = Year(tarih1)
Date1_Month = Month(tarih1)
Date1_Day = Day(tarih1)
Date2_Year = Year(tarih2)
Date2_Month = Month(tarih2)
Date2_Day = Day(tarih2)
If (Date1_Month = 12) and (Date1_Day = 31) and
(Date2_Month = 1) and (Date2_Day = 1) Then
NoOfyears = Date2_Year - Date1_Year - 1
NoOfmonths = 0
NoOfdays = 1
Else
NoOfyears = Date2_Year - Date1_Year
NoOfmonths = Date2_Month - Date1_Month
NoOfdays = Date2_Day - Date1_Day
End If
If NoOfyears = 1 Then
FormatString = "1 year "
Else If NoOfyears <= 0 then
FormatString = ""
Else
FormatString = CStr(NoOfyears) & " years "
End If:End If
If NoOfmonths = 1 Then
FormatString = FormatString & "1 month"
Else If NoOfmonths <= 0 then
FormatString = FormatString
Else
FormatString = FormatString & CStr(NoOfmonths) & " months "
End If:End If
if useDates=1 then
If NoOfdays = 1 Then
FormatString = FormatString & "1 day"
Else If NoOfdays <= 0 Then
FormatString = FormatString
Else
FormatString = FormatString & CStr(NoOfdays) & " days"
End If:End If
end if
end if
end if
Convert_Date_to_Text = FormatString
End Function
このウェブサイトは違いを完全に計算します。TimeAndDate.Com
注:いくつかの理由でClassic ASPを使用しています(会社の制限)。申し訳ありませんが、ASP関数が必要です。TimeSpanはASPに存在しないようです:(
敬具