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

Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
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



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

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