the last saturday in the month

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

the last saturday in the month

turbofib
hi,

i would to know if a serial data is the last Saturday in the month

how can i code it?

g=Serial Data



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

marco atzeri-2
Am 07.08.2018 um 07:55 schrieb turbofib:
> hi,
>
> i would to know if a serial data is the last Saturday in the month
>
> how can i code it?
>
> g=Serial Data
>

If I correctly understood your question,
using today as reference "Serial Data"

octave:21> a=localtime(time())
a =

   scalar structure containing the fields:

     usec =  747239
     sec =  21
     min =  7
     hour =  12
     mday =  7
     mon =  7
     year =  118
     wday =  2
     yday =  218
     isdst =  1
     gmtoff =  7200
     zone = CEST

octave:23> b=eomday(a.year+1900,a.mon+1)
b =  31

The "date" is the last Saturday of the month if
  (a.wday == 6) & (a.mon+7>b)


https://octave.org/doc/v4.4.0/Timing-Utilities.html

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
i've a a serial number:

example:

A=733546;

now i want create a function that return true if it's the last Saturday in
the month

i want to use  datestr to code it






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

marco atzeri-2
Am 07.08.2018 um 12:57 schrieb turbofib:

> i've a a serial number:
>
> example:
>
> A=733546;
>
> now i want create a function that return true if it's the last Saturday in
> the month
>
> i want to use  datestr to code it
>

Now it looks almost an homework, and we do not do it for you.

As I gave you a guidance how to calculate it, why do you need datestr
and what is your problem to write a function ?

Regards
Marco




---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
This post was updated on .
Correct!


I'll give you this example because there are several problems I've found
Anyway I can write the problems in a separate way so I do it :)

If i write :

 datestr(733546,8)=="Sat"  
ans=1 0 0

i want to return true or false
instead it return a boolean matrix

https://gyazo.com/ea88163126129782507c25ba302890af





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

Doug Stewart-4


On Tue, Aug 7, 2018 at 9:05 AM, turbofib <[hidden email]> wrote:
Correct!


I'll give you this example because there are several problems I've found
Anyway I can write the problems in a separate way so I do it :)

If i write :

 datestr(733546,8)=="Sat" 
ans=1 0 0

i want to return true or false
instead it return a boolean matrix


 
If you use google  or any search engine with this:

octave string compare

then you get an answer!!! 



--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

gciriani
In reply to this post by turbofib
Turbofib,
The reason you get the vector 1 0 0 is that datestr(733546,8) is the string
"Sun" and you are comparing it to the string "Sat". String comparison then
treats the comparison as a vector with each element of the vector 1 if the
letters in that position are identical, or 0 if they are different.



-----
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

Doug Stewart-4
In reply to this post by Doug Stewart-4


On Tue, Aug 7, 2018 at 9:37 AM, Doug Stewart <[hidden email]> wrote:


On Tue, Aug 7, 2018 at 9:05 AM, turbofib <[hidden email]> wrote:
Correct!


I'll give you this example because there are several problems I've found
Anyway I can write the problems in a separate way so I do it :)

If i write :

 datestr(733546,8)=="Sat" 
ans=1 0 0

i want to return true or false
instead it return a boolean matrix


 
If you use google  or any search engine with this:

octave string compare

then you get an answer!!! 


--
DAS

also 
Inside octave you can do:
>> lookfor string compare

and scroll down to str****


I am just showing you how I get my answers :-)




--
DAS



Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
In reply to this post by gciriani
Thanks all..


I'm not very practical with regards to strings :(

now it's ok! i'm understand!





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

gciriani
In reply to this post by turbofib
Turbofib,
There is no need to use datestr, because you admitted you already have the
date number, in your example you gave 733546.

So if you use d = 733546 then Marco Atzeri's solution is the correct one
which using d as your date variable, in a compact way would become
d = 733546;
a = localtime(d);
b = eomday(a.year+1900,a.mon+1);
Last_Saturday = (a.wday == 6) & (a.mon+7>b)




-----
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
hi ciriani

to use localtime is not correct

see this example:

737234 is serial number of : 23/06/2018

localtime(737234) =

usec = 0
    sec =  14
    min =  47
    hour =  13
    mday =  9
    mon = 0
    year =  70
    wday =  5
    yday =  8
    isdst = 0

https://gyazo.com/59b4494e1e2a3f05448ce3dd46be67a0



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

marco atzeri-2


Am 07.08.2018 um 16:59 schrieb turbofib:
> hi ciriani
>
> to use localtime is not correct
>
> see this example:
>
> 737234 is serial number of : 23/06/2018

why do you think so ?

>
> localtime(737234) =
>
> usec = 0
>      sec =  14
>      min =  47
>      hour =  13
>      mday =  9
>      mon = 0
>      year =  70
>      wday =  5
>      yday =  8
>      isdst = 0
>

it is 1970 Jan 9

---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
Hi marco

Look that.

>> datestr(737234,7)  ====> it give me number day
ans = 23
Day:23

You say:

it is 1970 Jan 9  

Day: 9



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

gciriani
So there is an offset between the two, and also localtime is in seconds. You
need to calculate the offset and multiply by 3600*24 and use that as the
input for localtime.



-----
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

turbofib
i think is better to use datestr






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: the last saturday in the month

gciriani
Turbofib,
If you don't mind show us what you have come with once you elaborate your
solution based on our help.



-----
Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32
--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Giovanni Ciriani - Windows 10, Octave 4.2.1, configured for x86_64-w64-mingw32