Click to See Complete Forum and Search --> : Selecting Date and time


wan2fly99
04-01-2005, 10:19 AM
I would like to retrieve the current date and time using asp.

I then would like to take the yymm part from the date
and the hhmm from the time field.

I think you do this using the substr function?

Would like the final result to look like:

yymmhhmm as the field

Any help is appreciated

Thanks

buntine
04-01-2005, 10:40 AM
The keyword Now will return the current date and time. Alternatively, you can use the Date and Time functions, respectively. VBScript has a bunch of handy date handling functions that we can use here.

Dim dteCurrDate, dteCurrTime
Dim strOutput
dteCurrDate = Date
dteCurrTime = Time

strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
CStr(Month(dteCurrDate)) & _
CStr(Hour(dteCurrTime)) & _
CStr(Minute(dteCurrTime))

Response.Write(strOutput)

Note, hours are in 24-hour time. 3PM = 15.

Give that a shot.

Regards.

wan2fly99
04-01-2005, 10:59 AM
Thanyou very much sir, it would have taken me the whole night tonight
at ome to figure it out.

I am just learning ASP and VB on the side, as I do mainframe work (dinasour)

I have to read, look at examples.

Thanks again

buntine
04-01-2005, 11:04 AM
Your welcome. ;)

wan2fly99
04-02-2005, 08:22 AM
One more quick question.

The month returns values from 1 - 12, how can I get say month 01,02,03...

Also hiurs, minutes and second, like to get lead 0 in so I can make my key a
uniform length

buntine
04-02-2005, 09:36 AM
The way I do it is via a function I call prefixZero(...).

Dim dteCurrDate, dteCurrTime
Dim strOutput
dteCurrDate = Date
dteCurrTime = Time

Public Function PrefixZero(num)
Dim newNum
If (CInt(num) < 10)
PrefixZero = "0" & num
Else
PrefixZero = num
End If
End Function

strOutput = Right(CStr(Year(dteCurrDate)), 2) & _
PrefixZero(CStr(Month(dteCurrDate))) & _
PrefixZero(CStr(Hour(dteCurrTime))) & _
PrefixZero(CStr(Minute(dteCurrTime)))

Response.Write(strOutput)

That should work alright.

Regards.

wan2fly99
04-02-2005, 02:29 PM
Thanks, I had started to setup a select case, but this is much simpler

buntine
04-02-2005, 11:02 PM
;)