SQL PHP HTML ASP JavaScript articles and free scripts to download
ASP > Date Today

Getting Weekday names by using WeekDay and WeekDayName functions in ASP

From a date variable or from a date we can get the weekday number staring from Sunday as 1 and Saturday as 7 ( see the table at the end ) by using weekday() function. Here is the syntax of weekday function.


Here we have taken one date but we can also use any date variable as input to the WeekDay function. Like this


Here d_mydate is a date variable and we can assign any date value to it.

The output of this function will be between 1 and 7 depending on the weekday of the input value. The example


The output of above line is 3. It represents Tuesday of the week. To get directly the name of the weekday we can use WeekDayName() function. This function takes the number of weekday and returns the name of the weekday. Here is the syntax of WeekDayName() function.

WeekDayName(weekday_number, type)

Here weekday_number is the variable holding the weekday number, type is an optional Boolean argument to specify long or short name of the weekday to be returned. False value of type returns Long name and True value returns short name. By default it is set to False. Here are some examples of WeekDayName function.

Response.Write WeekDayName(4)

This will give output Wednesday

Response.Write WeekDayName(4,True)

This will give output Wed

Response.Write WeekDayName(5,False)

This will give output Thursday

Now let us try to print the name of the weekday from a date variable or date by using both WeekDay() and WeekDayName() function. Here is the code.

Dim d_mydate
Response.Write WeekDayName(WeekDay(d_mydate))

This will print long name of the weekday of today.

Table for WeekDays function values

Be the first to post comment on this article :


Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer