Printing variable values
In previous lesson we saw how we can print
value of a variable to output page.
If we have a variable "test" we can print
its value with two methods.
If we want to print it in html part of our
ASP program we will use <%=…%> tags.
<p align=center>Value of variable is:
If we want to print value of a variable in
vbscript section of our ASP program we may use "response" object to do
this. In fact we will use one of methods of this object. We
will speak more about response.object in next sections.
If look at our 1-5 example in our previous
lesson, you will find that this is what we have done in that example.
<script language="vbscript" runat="server">
I want to say: <br>
An object is formed of properties (variable
members of an object) and methods (function and procedure members of
an object). Response object will be used for sending any type of data
to web browser.
Date and Time variables
Now that we have seen how we can print
variables to output, we can work with some of useful internal ASP
First variable that we want to test is
Today is <%=date%>
Today is 7/12/2001
You can use "time" variable in the same way you
Time is <%=time%>
Time is 7:57:52 PM
If you need both date and time in your output,
you can use "now" variable instead.
Now is <%=now%>
Now is 7/12/2001 7:59:18 PM
Vbscript is a language derived from
"Basic" programming language. As you may know there are many
instructions or in fact functions in this language that work on
For example, in "Basic" language we have
many functions that manipulate a string variable. There are functions
that return a part of a string, truncate spaces from its end or start,
find a sub string in it, and etc.
We will study most of useful vbscript
functions in this course.
In previous section we learned a few of
vbscript internal variables. In next section we are going to see some
functions related to time and date
Let's start this section with a
Look at this example:
Now is : <%=now%> <br><br>
Day : <%=day(now) %> <br>
Day : <%=day(date) %> <br>
month: <%=month(now)%> <br>
month: <%=month(date)%> <br>
Year: <%=year(now) %> <br>
Year: <%=year(date) %>
Month Number: <%=month(now)%>
Month Name: <%=monthname(month(now))%>
Month Name: <%=monthname(month(date))%>
Week Day Number:
Week Day Name:
Now is : 7/12/2001 8:11:33 PM
Time: 8:11:33 PM
Day : 12
Day : 12
Month Number: 7
Month Name: July
Month Name: July
Week Day Number: 5
Week Day Name: Thursday
If you look at both source code and output
you will find what each function does. We have gathered a summary of
time functions and variables here.
'now' gives current time and date (variable)
'date' gives current date (variable)
'time' gives current clock time. (variable)
'day(…)' returns day section of time in
'month(…)' gives the month section of a date
in number format
'year(…)' gives the year section of a date
'monthname(…)' gives name of a month number in
string format i.e. January, …
'weekdayname(…)' gives name of a week day in
string format ie. Sunday,…
If you want to use above functions on a given
time, you can do this in the same way we have done in below example.
My birth day was on <%=birth%><br>
And it was
My birth day was on 10/12/1971
And it was 12 October, 1971
This is another example that uses a specified
time value with above functions.
My work starts at <%=work%><br>
It is at
My work starts at 6:04:34
It is at 6,12,34
In next lesson we will start with some
vbscript string functions and then we will proceed to more complicated
1- Rewrite example 2-5 to
use response.write for sending output to web pages. Use example 1-5
as a template.
2- Write an ASP program,
which has a 'startcounting' sub program. Whenever you call this sub
program it writes the names of weekdays on output web page.
Use weekdayname() function.