Tom Knowlton
asked on
Convert DateTime value to strings
Here is my current VBA conversion
lngGameBoardNumber = Format(Date, "yyyy") + Format(Date, "mm") + Format(Date, "dd") + Format(Time, "hh") + Format(Time, "nn") + Format(Time, "ss")
This means that tody's date + time would be converted to:
20030621103843
in 5 seconds it would look like
20030621103848
But I want to change this so it will work under ASP / VBScript:
lngGameBoardNumber = Format(Date, "yyyy") + Format(Date, "mm") + Format(Date, "dd") + Format(Time, "hh") + Format(Time, "nn") + Format(Time, "ss")
This means that tody's date + time would be converted to:
20030621103843
in 5 seconds it would look like
20030621103848
But I want to change this so it will work under ASP / VBScript:
Use FormatDateTime(lngGameBoar dNumber,vb longtime)
try this
<%
lngGameBoardNumber = Year(Date) & Month(Date) & Day(Date) & Hour(Time) & Minute(Time) & Second(Time)
response.write lngGameBoardNumber
%>
hongjun
<%
lngGameBoardNumber = Year(Date) & Month(Date) & Day(Date) & Hour(Time) & Minute(Time) & Second(Time)
response.write lngGameBoardNumber
%>
hongjun
Or do you mean
lngGameBoardNumber = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h) & DatePart(Time, "n") & DatePart(Time, "s")
lngGameBoardNumber = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h) & DatePart(Time, "n") & DatePart(Time, "s")
ASKER
I get:
sGameNum = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h) & DatePart(Time, "n") & DatePart(Time, "s") Set oGenID = Nothing
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -^
sGameNum = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h) & DatePart(Time, "n") & DatePart(Time, "s") Set oGenID = Nothing
--------------------------
sGameNum = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h") & DatePart(Time, "n") & DatePart(Time, "s")
hongjun
hongjun
ASKER
nevermind...caught the bug...
testing it now...
testing it now...
You may also wish to consider my first comment.
It should be this
sGameNum = DatePart("YYYY", Date) & DatePart("M", Date) & DatePart("D", Date) & DatePart("H", Time) & DatePart("N", Time) & DatePart("S", Time)
hongjun
sGameNum = DatePart("YYYY", Date) & DatePart("M", Date) & DatePart("D", Date) & DatePart("H", Time) & DatePart("N", Time) & DatePart("S", Time)
hongjun
The interval should be the first argument.
hongjun
hongjun
ASKER
Well, I thought I had it fixed. Now I get:
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "yyyy"]'
/robotzgame/game.asp, line 75
Here is the current code:
Dim sGameNum
sGameNum = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h") & DatePart(Time, "n") & DatePart(Time, "s")
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "yyyy"]'
/robotzgame/game.asp, line 75
Here is the current code:
Dim sGameNum
sGameNum = DatePart(Date, "yyyy") & DatePart(Date, "m") & DatePart(Date, "d") & DatePart(Time, "h") & DatePart(Time, "n") & DatePart(Time, "s")
knowlton, see the code above.
ASKER
Oooooops.
I'll make the change!
Tom
I'll make the change!
Tom
Use either
<%
sGameNum = Year(Date) & Month(Date) & Day(Date) & Hour(Time) & Minute(Time) & Second(Time)
response.write sGameNum
%>
OR
<%
sGameNum = DatePart("YYYY", Date) & DatePart("M", Date) & DatePart("D", Date) & DatePart("H", Time) & DatePart("N", Time) & DatePart("S", Time)
response.write sGameNum
%>
hongjun
<%
sGameNum = Year(Date) & Month(Date) & Day(Date) & Hour(Time) & Minute(Time) & Second(Time)
response.write sGameNum
%>
OR
<%
sGameNum = DatePart("YYYY", Date) & DatePart("M", Date) & DatePart("D", Date) & DatePart("H", Time) & DatePart("N", Time) & DatePart("S", Time)
response.write sGameNum
%>
hongjun
ASKER
Okay...it works....but still needs ONE tweak.
I need the Month, Day, Hour, Minutes, and Seconds to be formatted at ## instead of #
for example, June would be
06
instead of
6
Can DatePart handle this?
I need the Month, Day, Hour, Minutes, and Seconds to be formatted at ## instead of #
for example, June would be
06
instead of
6
Can DatePart handle this?
Try this
<%
sGameNum = DatePart("YYYY", Date) & Right("0" & DatePart("M", Date), 2) & Right("0" & DatePart("D", Date), 2) & Right("0" & DatePart("H", Time), 2) & Right("0" & DatePart("N", Time), 2) & Right("0" & DatePart("S", Time), 2)
response.write sGameNum
%>
hongjun
<%
sGameNum = DatePart("YYYY", Date) & Right("0" & DatePart("M", Date), 2) & Right("0" & DatePart("D", Date), 2) & Right("0" & DatePart("H", Time), 2) & Right("0" & DatePart("N", Time), 2) & Right("0" & DatePart("S", Time), 2)
response.write sGameNum
%>
hongjun
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great, thanks.
Tom
Tom
ASKER
50 more points for your trouble.