Randall-B
asked on
Convert Timestamp String to Regular Date & Time Format in ASP Classic
In ASP 3 with VB Script, how do I convert a timestamp string like
2007-03-29 17:30:21
to standard date format like
03-29-2007 05:30 PM ?
For example, in PHP I could do:
$string = "2007-03-29 17:30:21";
$updated = date('m-d-Y h:i A', strtotime($string) );
What is the ASP equivalent? Thanks.
2007-03-29 17:30:21
to standard date format like
03-29-2007 05:30 PM ?
For example, in PHP I could do:
$string = "2007-03-29 17:30:21";
$updated = date('m-d-Y h:i A', strtotime($string) );
What is the ASP equivalent? Thanks.
Or if you like living dangerously you can depend on the computer settings as in:
MsgBox FormatDateTime(CDate("2007 -03-29 17:30:21"), vbGeneralDate)
MsgBox FormatDateTime(CDate("2007
ASKER
ryancys,
Thanks; that works great except it is not converting "17" to "05" in "17:30:21". I would like it to output: 03-29-2007 05:30 PM (with the "05"). Thanks.
Thanks; that works great except it is not converting "17" to "05" in "17:30:21". I would like it to output: 03-29-2007 05:30 PM (with the "05"). Thanks.
ASKER
acperkins,
Thanks for the alternate suggestion. As you noted, depending on the computer settings might be risky, as each user could different settings, so I'll go with the method ryancys suggested. Thanks again.
Thanks for the alternate suggestion. As you noted, depending on the computer settings might be risky, as each user could different settings, so I'll go with the method ryancys suggested. Thanks again.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ryancys,
That's it. Thanks!
That's it. Thanks!
<%
str = "2007-03-29 17:30:21"
strDate = cDate(str)
newstr = right("0" & month(strDate),2) & "-" & right("0" & day(strDate),2) & "-" & right("00" & year(strDate),4) & " " & right("0" & hour(strDate),2) & ":" & right("0" & minute(strDate),2) & " "
if hour(strDate) > 12 then
newstr = newstr & "PM"
else
newstr = newstr & "AM"
end if
response.write str & " to " & newstr
%>