SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.

WeekDay(#7/25/2006#)


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

WeekDay(d_mydate)


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

WeekDay(#7/25/2006#)


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
d_mydate=Now
Response.Write WeekDayName(WeekDay(d_mydate))
This will print long name of the weekday of today.

Table for WeekDays function values
ValueMeaning
1Sunday
2Monday
3Tuesday
4Wednesday
5Thursday
6Friday
7Saturday
Further readings
Getting todays Date and Time based on local settings
Formatting date and time on local settings
Adding Date intervals using DateAdd function
Finding difference between two dates using DateDiff function
Collecting parts of Date by using DatePart function
Collecting Month name by using Month number by MonthName function
Collecting Name of the weekday of any Date by WeekDayName function
Generating Date variables by using Month, Day and Year Value
Function IsDate to check valid date or date variable
Checking user entered date value
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.