Source language: Translate to:

get number of days on a month?

General questions about NeoBook

Moderator: Neosoft Support

get number of days on a month?

Postby yanzco » Thu Dec 18, 2014 8:16 am

wondering how i can get the number of days of a specific month..

like if i entered january of 2015... it shows 31 days
december of 2014.. has 31 days
yanzco
 
Posts: 175
Joined: Sun Jul 20, 2014 4:07 am

Re: get number of days on a month?

Postby mishem » Thu Dec 18, 2014 8:34 am

yanzco wrote:january of 2015


Code: Select all
DateToNum "1.01.15" "d/m/y" "[Result]"
DateToNum "1.02.15" "d/m/y" "[Result2]"
SetVar "[Result]" "[Result2]-[Result]"


yanzco wrote:december of 2014


Code: Select all
DateToNum "1.12.14" "d/m/y" "[Result]"
DateToNum "1.01.15" "d/m/y" "[Result2]"
SetVar "[Result]" "[Result2]-[Result]"


February

Code: Select all
DateToNum "1.02.14" "d/m/y" "[Result]"
DateToNum "1.03.14" "d/m/y" "[Result2]"
SetVar "[Result]" "[Result2]-[Result]"


etc.

Get the day of the week on the specified date.

Code: Select all
.1. Обозначим число, месяц и год соответственно d, m и y.
.2. Если m <= 2 (т.е. месяц январь или февраль), то год уменьшим на 1, а число увеличим на 3:
.    y:= y–1;
.    d:= d+3;
.3. Теперь номер дня недели (w) вычисляется по следующей формуле:
.   w:= 1 + [d + y + y/4 – y/100 + y/400 + (31m+10)/12] mod 7;
.(все операции деления — целочисленные, т.е. берется целая часть частного; mod — операция получения остатка от деления).

.Результатом будет целое число в диапазоне от 1 до 7, соответствующее дням недели от воскресенья до субботы
.(1 — понедельник, 2 — вторник, 3 — среда, 4 — четверг, 5 — пятница, 6 — суббота, 7 — воскресенье).

If "[m]" "<=" "2"
     SetVar "[y]" "[y]-1"
     SetVar "[d]" "[d]+3"
EndIf

Math "[d]+[y]+Trunc([y]/4)-Trunc([y]/100)+Trunc([y]/400)+Trunc((31*[m]+10)/12)" "0" "[Result]"
Math "[Result]-Trunc([Result]/7)*7+1" "0" "[Result]"


Comments perevedesh himself if necessary.
Comments on the Russian language.
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

Re: get number of days on a month?

Postby stu » Thu Dec 18, 2014 9:18 am

I guess the wasy way would be...

npUtil

Code: Select all
npDaysInAMonth "" "" ""


:wink:
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am

Re: get number of days on a month?

Postby mishem » Thu Dec 18, 2014 9:41 am

We are not looking for easy ways ...

:)
mishem
 
Posts: 574
Joined: Mon Oct 08, 2012 1:51 pm

Re: get number of days on a month?

Postby dpayer » Thu Dec 18, 2014 10:20 am

yanzco wrote:wondering how i can get the number of days of a specific month..

like if i entered january of 2015... it shows 31 days
december of 2014.. has 31 days



Mishem's answer is good.

If you'd like to see some other tools regarding dates, take a look at a function I made for a popup calendar.

http://neosoftware.com/community/viewto ... 22&t=20140
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: get number of days on a month?

Postby yanzco » Thu Dec 18, 2014 10:22 am

thanks mishem!! that was clever... why did i not think of that before.. haha..

thou i dont understand the russion one.. :O
yanzco
 
Posts: 175
Joined: Sun Jul 20, 2014 4:07 am

Re: get number of days on a month?

Postby yanzco » Thu Dec 18, 2014 10:23 am

dpayer wrote:If you'd like to see some other tools regarding dates, take a look at a function I made for a popup calendar.
http://neosoftware.com/community/viewto ... 22&t=20140


thanks dpayer.. ill check on that.. :D
yanzco
 
Posts: 175
Joined: Sun Jul 20, 2014 4:07 am

Re: get number of days on a month?

Postby Gaev » Thu Dec 18, 2014 10:25 am

mishem's solution can be made "easy" by doing a GoSub like this ...
Code: Select all
SetVar "[thisYear]" "2015"
SetVar "[thisMonth]" "1"
GoSub "mishemDaysInMonth"

... result in [mishemDaysInMonthResult]

An even better solution would be to set up a NeoBook Function ... and then Call it like ...
Code: Select all
Call "mishemDaysInMonth" "[thisYear]" "[thisMonth]" "[thisVarForAnswer]"


Since it is mishem's original idea/code, perhaps he can post the subroutine and function code :wink:
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: get number of days on a month?

Postby stu » Thu Dec 18, 2014 10:40 am

mishem wrote:We are not looking for easy ways ...

:)


Fair enough...

Image
User avatar
stu
 
Posts: 318
Joined: Wed Aug 07, 2013 11:37 am

Re: get number of days on a month?

Postby David de Argentina » Thu Dec 18, 2014 11:25 am

More simple: Save into the function folder as LastDayOfMonth

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
{NeoBook Function}
Version=5.80
Language=NeoBook
Param=[%1]|Text|Date
Param=[%2]|Variable|Return Var
{End}
DefineVar "[NormalDate]" "Date" "dd/mm/yyyy" "Local" ""
DefineVar "[FirstDayNextMonth]" "Date" "dd/mm/yyyy" "Local" ""
DefineVar "[NumDate]" "Integer" "" "Local" ""
DefineVar "[c_Day]" "Integer" "" "Local" ""
DefineVar "[c_Month]" "Integer" "" "Local" ""
DefineVar "[c_Year]" "Integer" "" "Local" ""
DefineVar "[c_Year2]" "Integer" "" "Local" ""
DefineVar "[c_NextMonth]" "Integer" "" "Local" ""
DefineVar "[Num_FirstDayNextMonth]" "Integer" "" "Local" ""
DefineVar "[Num_LastDayofMonth]" "Integer" "" "Local" ""

DateToNum "[%1]" "Default" "[NumDate]"
NumToDate "[NumDate]" "dd/mm/yyyy" "[NormalDate]"

SubStr "[NormalDate]" "1" "2" "[c_Day]"
SubStr "[NormalDate]" "4" "2" "[c_Month]"
SubStr "[NormalDate]" "7" "4" "[c_Year]"

Math "[c_Month]+1" "0" "[C_NextMonth]"

If "[C_NextMonth]" "=" "13"
  SetVar "[C_NextMonth]" "01"
  Setvar "[C_Year2]" "[C_Year]+1"
else
  Setvar "[C_Year2]" "[C_Year]"
endif

Setvar "[FirstDayNextMonth]" "!01/[c_NextMonth]/[c_Year2]"

DateToNum "[FirstDayNextMonth]" "dd/mm/yyyy" "[Num_FirstDayNextMonth]"

Setvar "[Num_LastDayofMonth]" "[Num_FirstDayNextMonth]-1"

NumToDate "[Num_LastDayofMonth]" "dd" "[%2]"

 
Parsed in 0.010 seconds, using GeSHi 1.0.8.10


Usage:

Code: Select all
Call "LastDayOfMonth" "[Input_Date]" "[Output_Number]"



My (13X) devaluated cent,
David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: get number of days on a month?

Postby yanzco » Thu Dec 18, 2014 6:27 pm

very much help indeed.. thanks David :D
yanzco
 
Posts: 175
Joined: Sun Jul 20, 2014 4:07 am

Re: get number of days on a month?

Postby yanzco » Thu Dec 18, 2014 7:31 pm

a bit off topic.. with gaev and david's fuction.. is it possible to also know what day a day is?

like 12-19-2014 = december 2014 has 31 days.. and 19 is a friday..
12-20-2014 = december 2014 has 31 days.. and 19 is a saturday..
yanzco
 
Posts: 175
Joined: Sun Jul 20, 2014 4:07 am

Re: get number of days on a month?

Postby David de Argentina » Thu Dec 18, 2014 10:44 pm

Replace the last line of my function:

NumToDate "[Num_LastDayofMonth]" "dd" "[%2]"

with:

NumToDate "[Num_LastDayofMonth]" "dddd" "[%2]"

Enjoy !

David de Argentina
User avatar
David de Argentina
 
Posts: 1553
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: get number of days on a month?

Postby MiNeoBook » Fri Dec 19, 2014 10:22 am

Esto me trabaja bien
Code: Select all
setvar "[dd]" "31"
.. In TextEntry
... [yy]   14
... [mm]   2

:Day
DateToNum "[dd]/[mm]/[yy]" "d/m/y" "[dmy]"
if "[Dmy]" "=" "Error"
    math "[dd]-1" "" "[dd]"
    gotoline "Day"
endif
Alertbox "" "Month [Mm] With [DD] Days"
MiNeoBook
 
Posts: 7
Joined: Mon Dec 08, 2014 9:40 am


Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron