Source language: Translate to:

What Day is this Date?

General questions about NeoBook

Moderator: Neosoft Support

What Day is this Date?

Postby TMcD » Thu Oct 30, 2014 4:27 pm

I need to take a date, such as:

10/13/2013
6/5/2012

And find what day of the week it is (IE: Sunday, Monday, Tuesday, etc.)

I searched and found old posts that had links to now defunct stuff.

I looked online for a formula, but the thing that had me scared was the mention of the formula not working with Gregorian dates/Leap year or something like that.

I need it to be "dead on correct" and I know it can be done without purchasing a plugin.

Anyone have the formula around?

Thanks,
Troy

P.S. I thought I'd add the "end goal" here:

The end goal is to grab some images from a web site, but only grab the images created Monday through Friday, using the starting day and ending day given.

Example

Start Day = 01/02/13
End Day = 02/01/13
(Roughly 30 days)

The images on Saturday an Sunday between the date range are the same as Friday's image. I don't want duplicates stored.

So, I'd just like to look through the start and end dates, check if it's Saturday or Sunday, if so, skip that image.

* The Start and End Days can be all over the map, not just current year or month.
TMcD
 
Posts: 237
Joined: Sun Apr 10, 2005 11:20 am

Re: What Day is this Date?

Postby Gaev » Thu Oct 30, 2014 5:11 pm

TMcD:

Javascript has all the functionality you need e.g. ...

Code: Select all
var thisDate = "10/29/2014";
var d = new Date(thisDate);

var dayOfWeek = d.getDay();
alert(dayOfWeek);

var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var weekDay = days[d.getDay()];
alert(weekDay);

This will result in ...

- dayOfWeek = 3
- weekDay = Wednesday

Note that you can use NeoBook's Call command to invoke a Function that can be written in Javascript.

If you need help with the exact function code, ask here.

As for your "end goal", you can ...

- use NeoBook's DateToNum command to Loop/EndLoop from your StartDate to your EndDate
- in each iteration, use NumToDate to convert it back to mm/dd/yyyy format ... and pass this date string to the Called Function
- if dayOfWeek (or weekDay) is as desired, do your thing with it
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: What Day is this Date?

Postby TMcD » Thu Oct 30, 2014 5:24 pm

Thanks Gaev.

I'll give it a try. I've never done any Javascript with NeoBook. First time for everything. 8)
TMcD
 
Posts: 237
Joined: Sun Apr 10, 2005 11:20 am

Re: What Day is this Date?

Postby TMcD » Thu Oct 30, 2014 9:17 pm

Wow man my head hurts... :shock:

I've been looking through the NeoBook Help, the discussion board and even the Resource Center

Here's an example I found:
viewtopic.php?f=1&t=20207&hilit=javascript+function

But man, I can't piece this together.

I'm not so versed in JavaScript, but it's the [%1] and just the non-explanation of what NeoBook needs. For example a lot of things I saw didn't show the need for:

Code: Select all
Language=JScript


I mean that makes sense, but the documentation is very very lacking.

It's a breeze to make a NeoBook function call, but again, big time lacking information JavaScript stuff. :cry:
TMcD
 
Posts: 237
Joined: Sun Apr 10, 2005 11:20 am

Re: What Day is this Date?

Postby TMcD » Thu Oct 30, 2014 10:06 pm

Ok, so I didn't give up... I'm gonna keep the above post, but I got it to work.

Things to note, when setting the date variable, you must you the "!" literal marker with the date.

So "10/15/2012" becomes "!10/15/2012"

Here is the JavaScript to grab the date and export the date back out to NeoBook (to be used as a Function):

Code: Select all
// Get date from NeoBook variable

var thisDate = nbGetVar( '[datetocheck]' );

var d = new Date(thisDate);

var dayOfWeek = d.getDay();

var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var weekday = days[d.getDay()];

// Set NeoBook Variable

nbSetVar("[datecheckedday]", weekday);


Thanks for Gaev getting me out on the correct path! :D

Troy
TMcD
 
Posts: 237
Joined: Sun Apr 10, 2005 11:20 am

Re: What Day is this Date?

Postby dpayer » Fri Oct 31, 2014 7:14 am

If you are interested in seeing how I solved this with just Neobook commands you can look at the popup calendar function I created:

viewtopic.php?f=22&t=20140
(see the subroutine used)

The DateToNum function and the counterpart NumToDate is how I addressed the issue.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: What Day is this Date?

Postby TMcD » Fri Oct 31, 2014 12:22 pm

Thanks David.

That sure is a piece of work. :)
TMcD
 
Posts: 237
Joined: Sun Apr 10, 2005 11:20 am

Re: What Day is this Date?

Postby Gaev » Fri Oct 31, 2014 4:50 pm

Troy:

I have created a post here that describes a NeoBook Function (written in JScript) that returns the Day Of Week (number and name) for a specified date.

In order to deploy this for your "end game", try this ...
Code: Select all
SetVar "[StartDate]" "!10/28/14"
SetVar "[EndDate]" "!11/03/14"

DateToNum "[StartDate]" "m/d/y" "[StartDateNum]"
DateToNum "[EndDate]" "m/d/y" "[EndDateNum]"

Loop "[StartDateNum]" "[EndDateNum]" "[thisDateNum]"
    NumToDate "[thisdateNum]" "m/d/yyyy" "[thisDate]"
    StrParse "[thisDate]" "!/" "[thisDateArray]" "[junk]"
    Call "gkDayOfWeek" "[thisDateArray3]" "[thisDateArray1]" "[thisDateArray2]" "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" "[thisDOWNumber]" "[thisDOWName]"
    IfEx "[thisDOWNumber] = 0 OR [thisDOWNumber] = 6"
       ... Sunday or Saturday
       AlertBox "gkDayOfWeek" "[thisDate] is a weekend ... [thisDOWNumber] ... [thisDOWName]"
    Else
       ... Monday to Friday
       AlertBox "gkDayOfWeek" "[thisDate] is a weekday ... [thisDOWNumber] ... [thisDOWName]"
    EndIf
EndLoop
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 1 guest