Paks
Paks

Reputation: 1470

Specific Date and Time in ASP Classic

Hi i have the following Code :

Dim CurrentDate
CurrentDate = Date()

Dim intHour
Dim intMinute
Dim intSecond

intHour = 17
intMinute = 0
intSecond = 0

Dim NewDate
Dim NewDate1
Dim NewDate2

NewDate = DatePart("yyyy", CurrentDate)
NewDate1 = DatePart("m", CurrentDate)
NewDate2 = DatePart("d", CurrentDate)


Dim Dates 

Dates = DateSerial(NewDate, NewDate1, NewDate2)

Dim Time 

Time = TimeSerial(intHour, intMonth, intSecond)

I have done something equal in VB:

    Dim value As Date = Date.Now
    Dim intHour As Integer
    Dim intMinute As Integer
    Dim intSecond As Integer


    intHour = 17
    intMinute = 0
    intSecond = 0

    Dim newdatetime As DateTime = New Date(value.Year, value.Month, value.Day, intHour, intMinute, intSecond)

In VB i can do

Dim newdatetime As DateTime = New Date(value.Year, value.Month, value.Day, intHour, intMinute, intSecond).

In my ASP Code i have Dates = DateSerial(NewDate, NewDate1, NewDate2) and Time = TimeSerial(intHour, intMonth, intSecond). How can i put them together as DateTime like in VB?

Upvotes: 1

Views: 4158

Answers (1)

feihtthief
feihtthief

Reputation: 7063

Two ways:

dim h,n,s
h = 17
n =  1
s =  2

dim t
t = timeserial(h,n,s)

dim d
d = date()
dim ts1
ts1 = dateadd("h",h, _
      dateadd("n",n, _
      dateadd("s",s, d )))
dim ts2
ts2 = d + T

Both produce the same output. The one with the additions has some gotchas depending on how close to day 0 you play it. I think the first way is "saner". As far as I recall VBScript just stored the date part in the integer or a float and the time part in the fraction part of a float (as parts of a 24 hour day, so 12:00 is 0.5), hence you can just add them together with +

Upvotes: 4

Related Questions