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.
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kulboyCommented:
check this:

Dim TestDateTime As Date = #1/27/2001 5:04:23 PM#
Dim TestStr As String
' Returns current system time in the system-defined long time format.
TestStr = Format(Now(), "Long Time")
' Returns current system date in the system-defined long date format.
TestStr = Format(Now(), "Long Date")
' Also returns current system date in the system-defined long date  
' format, using the single letter code for the format.
TestStr = Format(Now(), "D")

' Returns the value of TestDateTime in user-defined date/time formats.
' Returns "5:4:23".
TestStr = Format(TestDateTime, "h:m:s")
' Returns "05:04:23 PM".
TestStr = Format(TestDateTime, "hh:mm:ss tt")
' Returns "Saturday, Jan 27 2001".
TestStr = Format(TestDateTime, "dddd, MMM d yyyy")
' Returns "17:04:23".
TestStr = Format(TestDateTime, "HH:mm:ss")
' Returns "23".
TestStr = Format(23)

' User-defined numeric formats.
' Returns "5,459.40".
TestStr = Format(5459.4, "##,##0.00")
' Returns "334.90".
TestStr = Format(334.9, "###0.00")
' Returns "500.00%".
TestStr = Format(5, "0.00%")




especialy this one:
TestStr = Format(TestDateTime, "dddd, MMM d yyyy")
' Returns "17:04:23".

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
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'
kulboyCommented:
i would split up that line in peaces, and see where it fails.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AleksAuthor Commented:
I am not sure how to do that. I took out the time but still got the same issue.
AleksAuthor Commented:
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.
AleksAuthor Commented:
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
%>
AleksAuthor Commented:
Good try
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.