Get Day of Week for a specified Date

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Get Day of Week for a specified Date

Post by Gaev »

In this post, Troy asked about a function to get the Day Of the Week for a specified date.

The code below is for a NeoBook function (written in JScript) that can be Called for this purpose ...

Code: Select all

{NeoBook Function}
Version=5.80
Language=JScript
Param=[%FullYear]|Number|FullYear e.g. 2014
Param=[%Month]|Number|Month e.g. 1 or 2 or 12
Param=[%DayOfMonth]|Number|Day of Month e.g. 1 or 2 or 31
Param=[%NamesOfDays]|Text|Names of Days e.g. Sunday,Monday,Tuesday, ... Saturday
Param=[%DOWNumber]|Variable|Calculated Number of Day of Week
Param=[%DOWName]|Variable|Calculated Name of Day of Week
{End}
//gkDayOfWeek
var MonthBase0 = [%Month] - 1;

var dateObject = new Date([%FullYear], MonthBase0, [%DayOfMonth]);

nbSetVar('[%DOWNumber]', dateObject.getDay());

//var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var dayNames = "[%NamesOfDays]";
var days = dayNames.split(",");

nbSetVar('[%DOWName]', days[dateObject.getDay()]);
Copy and Save this text in a file called gkDayOfWeek in NeoBook's Function folder.

Then, whenever you wish to deploy it, do the following ...

Code: Select all

Call "gkDayOfWeek" "2014" "10" "29" "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" "[thisDOWNumber]" "[thisDOWName]"
... display results
AlertBox "gkDayOfWeek" "[thisDOWNumber] ... [thisDOWName]"
This format ...

a) avoids problems associated with differing date formats (by accepting year, month and date in 3 separate fields)

b) facilitates the return of names (of the days of the week) in your language of choice ... just start with whatever is Sunday in your language
Locked