Getting Weekday names by using WeekDay and WeekDayName functions in ASPFrom 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.
This will print long name of the weekday of today.
Be the first to post comment on this article :
|ASP Date & Time Functions|
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