Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Display date and time

I am using ASP/VB  and on my page I am trying to display the date and time, I am using:  <% =now %>
And that is great but it shows  9/18/2015 9:00:00 AM
And I need for it to be:  09/18/2015 9:00:00

And if its 8 pm it should be:   09/18/2015 20:00:00

I am not sure how to do this.
ASKER CERTIFIED SOLUTION
Avatar of kulboy
kulboy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

I actually have the following script, but its giving me an error when I try to display the value:

<script language="JavaScript" type="text/JavaScript">
function d2(n) { return n>9?n:"0"+n; }

function todayStr() {
     var today=new Date()
     return d2(today.getMonth()+1)+"/"+d2(today.getDate())+"/"+(today.getYear())+" "+ (formatAMPM(today))
} 

function formatAMPM(date) {
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var seconds = date.getSeconds();
  var ampm = hours >= 12 ? 'PM' : 'AM';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0'+minutes : minutes;
  var strTime = hours + ':' + minutes +':'+ seconds + ' ' + ampm;
  return strTime;
}

</script

Open in new window


Displaying:

value="<%=todayStr()%>"

Error:  Microsoft VBScript runtime error '800a000d'

Type mismatch: 'todayStr'
Avatar of kulboy
kulboy

i would split up that line in peaces, and see where it fails.
Avatar of Aleks

ASKER

I am not sure how to do that. I took out the time but still got the same issue.
Avatar of Aleks

ASKER

Can someone please help with the script ?   I can't seem to make that one work. I don't mind using a new one if needed.
Avatar of Aleks

ASKER

This worked:

<% function todayStr()
     dim theDate, theDay, theMonth
     theDate = FormatDateTime( now, 2)
     
     theMonth = Month(theDate)
     if CInt( theMonth ) < 10 then theMonth = "0" & theMonth

     theDay = Day( theDate )
     if CInt( theDay ) < 10 then theDay = "0" & theDay

     todayStr = theMonth & "/" & theDay & "/" & Year(theDate)&" "&formatdatetime(now,3)
end function
%>
Avatar of Aleks

ASKER

Good try