What are Active Server Pages? - Example 1
(Page 3 of 6 )
Example 1
Suppose you wanted to display today's date as day/month/year instead of month/day/year. To do so, you would use the day, month, and year ASP functions together, by typing:
<% =day(now) %>/<% =month(now) %>/<% =year(now) %>
When you view the page, you would see something like this:
23/1/1997
Later we'll see how you can change this so only the last two digits of the year are displayed, like this:
23/1/97
Weekday and Weekdayname
To display the day of the week as a number from 1 to 7 in a Web page, type:
<% =weekday(now) %>
where you want it to appear. When you view the page in Internet Explorer, you'll see a 1 if today is Sunday, 2 if it's Monday, and so on.
To display the day of the week by name, type:
<% =weekdayname(weekday(now)) %>
where you want it to appear.
Hour, Minute, and Second
To display just the hour part of the current time, type:
<% =hour(now) %>
where you want it to appear. The hour function is based on a 24-hour clock. When you view the page, you'll see a number between 0 and 23.
To display just the minutes part of the current time, type:
<% =minute(now) %>
where you want it to appear. When you view the page, you'll see a number between 0 and 59.
To display just the seconds part of the current time, type:
<% =second(now) %>
where you want it to appear. When you view the page, you'll see a number between 0 and 59.
Next: Examples 2, 3 and 4 >>
More ASP Articles
More By Sriram K