Forum - MCS Electronics

Author Message
KenHorse

Joined: 16 Jul 2004
Posts: 517

Posted: Sun Oct 04, 2020 6:22 pm    Post subject: Last occurrence of a day of the month

I've been using the following to determine the nth occurrence of a day of the month and it works well:

 Code: Function DayNameCountCurrentMonth() As Byte   Local Temp_day As Integer   Local Day_Name_Counter as Byte   Day_Name_Counter = 1   Temp_day = _day                                             'here we get a number from 1 to 31 (Current system date).   Temp_day = Temp_day - 7                                     'previous week   While Temp_day > 0     Incr Day_Name_Counter     Temp_day = Temp_day - 7                                  'previous week   Wend   DayNameCountCurrentMonth = Day_Name_Counter End Function

This makes it easy to determine, for example, the 3rd Wednesday of the month. Except I need to be able to determine the last occurrence of a day of the month (let's say the last Friday). As some months have 4 weeks and others have 5, well..that's my problem.

(BASCOM-AVR version : 2.0.8.3 )
MWS

Joined: 22 Aug 2009
Posts: 1864

Posted: Sun Oct 04, 2020 7:38 pm    Post subject: Re: Last occurrence of a day of the month

 KenHorse wrote: I've been using the following to determine the nth occurrence of a day of ethe month and it works well:

The shown function does nothing more than retrieving the n-th week in a month for a certain numbered day, it does not retrieve the name of said day.
 Quote: This makes it easy to determine, for example, the 3rd Wednesday of the month

'This' for sure not. Possible however in combination with other, not shown functions.
 Quote: Except I need to be able to determine the last occurrence of a day of the month (let's say the last Friday). As some months have 4 weeks and others have 5, well..that's my problem.

Calculate the date of the 5th occurence, then check if the result's month is the same as the month in request.
If not, the 4th occurence is valid.
I do remember this issue some while ago here in the forum.
Afair there were two competing solutions, my solution was to use Bascom's convert functions.
You may look that up, it provides the desired solution.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum