Source language: Translate to:

Get Day of Week for a specified Date

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Get Day of Week for a specified Date

Postby Gaev » Fri Oct 31, 2014 3:46 pm

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}
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
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
User avatar
Posts: 3757
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest