0

サーバーに常駐するカレンダープログラムがあります。このプログラムは、日付を次の形式でデータベースに保存します。

YYYYMMDD

これらの日付をaspで管理する「簡単な」方法はありますか? たとえば、日付として 2013 年 4 月 20 日があるとします。

20130420

この日付に 20 日を追加したいので、以下を作成します。

20130510

何か案が?aspにintegerTOdate変換はありますか? または、数字に「日」を追加するために使用できるものはあります20130420か?

4

3 に答える 3

2

はい、DateAdd機能を使用できます

Response.Write(DateAdd("d",1,Now()))

ただし、最初に日付を次のようにフォーマットする必要があります

<%
dim _dateOnServer
dim _formattedDate
dim _day
dim _month
dim _year

_dateOnServer = 20130420

_year = Left(_dateOnServer,4)
_month  =  Mid(_dateOnServer,5,2)
_day = Right(_dateOnServer,2)


_formattedDate =  _month &"-"& _day &"-"& _year

dim _newDate
_newDate =  DateAdd("d",20, _formattedDate )

_day = Left(_newDate,2)
_month  =  Mid(_newDate,4,2)
_year = Right(_newDate,4)

dim _newDateFormat
_newDateFormat = _year & _month & _day

%>
于 2013-04-15T14:29:41.383 に答える
1

順序とフォーマットを完全に制御できるソリューション...

strDay = Day(Date)
strMonth = Month(Date)
strYear = Year(Date)
strHours = Hour(Now)
strMins = Minute(Now)
strSecs = Second(Now())
    if len(strMonth) = 1 then
        strMonth = "0" & strMonth
    end if
    if len(strDay) = 1 then
        strDay = "0" & strDay
    end if
    if len(strHours) = 1 then
        strHours = "0" & strHours
    end if
    if len(strMins) = 1 then
        strMins = "0" & strMins
    end if
    if len(strSecs) = 1 then
        strSecs = "0" & strSecs
    end if

strDateAdded = strYear & "-" & strMonth & "-" & strDay
strDateAddedTime = strDateAdded & " " & strHours & ":" & strMins

この方法を使用すると、順序を完全に制御でき、Web アプリを異なるタイム ゾーンで実行している場合でも、DD/MM 形式を維持したり、MM-DD-YY などの任意の順序を維持したりできます (並べ替えとトリミングにより)。年)。個人的には YYYY-MM-DD を好みます。なぜなら、ASC と DESC による並べ替えの方が作業がはるかに簡単だからです。

2013-04-01 03:15
2013-04-09 10:15
2013-04-22 07:15
2013-04-23 10:15
2013-04-23 10:60
2013-10-25 12:01
2013-10-25 12:59

それ以外の:

2013-4-1 3:15
2013-4-9 10:15
2013-4-22 7:15
2013-4-23 10:15
2013-4-23 10:60
2013-10-25 12:1
2013-1-25 12:59
于 2013-04-29T08:40:06.103 に答える