Wednesday, August 5, 2009

ASP Format Date and Time

while coding on ASP we required date and time most of the time, how to get this is very basic and well known to the most of the Programmers, but how to get the only specific date , time in required format is a main task ,

for that we have inbuild function call FormatDateTime() .

now we very well knows if we want to get current date and time then we can use now()

<%dim TodayDnT
TodayDnT = now()
%>

if you want the Result of same then use <% Response.write(TodayDnT) %>
so it will return result as : - 8/5/2009 12:11 PM

now we have the option to format that
1. Using 0

<%
Response.write FormatDateTime(TodayDnT,0)
%>

Result : - 8/5/2009 12:11:10 PM


2. Using 1

<%
Response.write FormatDateTime(TodayDnT,1)
%>

Result :- Wednesday, August 12, 2009 (long date )


3. Using 2

<%
Response.write FormatDateTime(TodayDnT,2)
%>

Result: - 8/5/2009 (short date)


4. using 3

<%
Response.write FormatDateTime(TodayDnT,3)
%>

Result : - 12:11:10 PM (long time)


5. using 4

<%
Response.write FormatDateTime(TodayDnT,4)
%>

Result : - 11:10 (current time in 24 format (hh:mm)


If you want to change the Date and Time according to international location then
use session.lcid property

Ex : - <% session.lcid=1036 %>
which will set the Date n Time in French Format

here is the List of all the
International Location

No comments:

Post a Comment