Skip to main content
January 20, 2010
Question

Date format in American (ASP)

  • January 20, 2010
  • 1 reply
  • 426 views

OK so I know that this should be easy.

My computer is setup so that dates are displayed in english format dd/mm/yyyy.

I am designing ASP pages and want a readonly field that takes its value from =(now). he result is always in American format mm/dd/yyyy.

See code:

<td><span id="spryID">
            <input name="id" type="text" id="id" value="<%=(now)%>" readonly="readonly" />
          </span></td>

Output is always:

1/20/2010 09:34:52 AM and not 20/1/2010 09:34:52 AM

How can I format the output to get the corect format I require?

This topic has been closed for replies.

1 reply

Participant
January 21, 2010

I found a date utility function several years ago and just continually format it for my needs.  Give this a whirl:

' Drop this in an include file somewhere so you can reference it.

function amDate(varDate)
  if isNull(varDate) OR Trim(varDate) = "" OR varDate = "Null" THEN
     amDate = "Null"
  else
     amDate = Month(DateValue(varDate)) & "/" & Day(DateValue(varDate)) & "/" & Year(DateValue(varDate)) & " " & TimeValue(varDate)
  end if
end function

'Call the function as I have below:

<td><span id="spryID">
            <input name="id" type="text" id="id" value="<%=(amDate(now()))%>" readonly="readonly" />
          </span></td>


Hope that helps you,

Joe Jenkins

mrwebguy

January 21, 2010

Thanks Joe

Your function does exactly what I need.

Ian

Participant
January 21, 2010

Excellent, I'm glad I was able to help.

Thanks,

Joe Jenkins