First day of the week

Martin Obongita martin.obongita at yahoo.com
Wed Oct 16 21:34:37 UTC 2024


 Thanks Doug for the input. Using lists is very slow so @Kelly gave a snippet of using loops which are much faster. I celebrate all of you Omnis gurus.

Message View
dates   
   - Kelly BurgessTo me · Mon, Oct 14 at 3:26 PM   
Message Body
Hi Martin,   
   
something like this?   
   
Kelly   
   
   
Do dayList.$define(date)   
# start on January 1st   
Calculate date as dat(con('1/1/',dty(#D)))  ## (assumes #FD is m D y)   
Calculate day as dtw(date)   
# find first Monday   
While day<>1   
  Calculate date as dadd(kDay,1,date)   
  Calculate day as dtw(date)   
End While   
# add all the Mondays   
While dty(#D)=dty(date)   
  Do dayList.$add(date)   
  Calculate date as dadd(kWeek,1,date)   
End While





    On Tuesday, October 15, 2024 at 06:39:09 PM GMT+3, Doug Easterbrook via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:  
 
 hi Martin

you said you fond a way around it….  Not sure what you used, but you can use this function to find the first day of the week for any date. 


Calculate lDate as fday(kWeek,#D)
# returns May 4, 2003 if the start of the week is set to Sunday


So, as you said, you could create a list of all days in the year, along with the first day of the week for that date, and deduplicate the list by sorting on the first day of the week column using something like

Since there can be leap years, I stuck 366 days into the list before removing duplicates.  I tihnk this assumes first day of week is a ’sunday'

Calculate startDate as 'Jan 1 2024'
Do list.$define(date1,date2)
For loop1 from 1 to 366
Do list.$add(startDate+loop1-1,fday(kWeek,startDate+loop1-1))
End For
Do list.$cols.date2.$removeduplicates(kTrue)



if your start of week is a monday or tuesday, (not sunday), then you might be able to use the pDay() function .    had to do something like this since most movies premier on Fridays and movie theatres declate their weeks to be monday to sunday.

eg 

Calculate lDate as pday(kThursday,#D)
# returns May 1 2003, which is the Thursday before #D, assume #D is May 8, 2003



or you can change the start day of the week for all the date functions using setws() and getws() … but that has a wider remification

Calculate lDate as setws((kMonday)
# set the beginning of the week to Monday
 
Calculate lDate as getws()
# returns 13, the value of the constant kMonday



I only bring this up for a wider audience since there are date functions that can set start of week, fiscal year etc that most may not know exist.






Doug Easterbrook
Arts Management Systems Ltd.
mailto:doug at artsman.com
http://www.artsman.com
Phone (403) 650-1978

> On Oct 14, 2024, at 3:35 AM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
> 
> Hi @all,
> Please ignore this. I found a way round it by using lists.
> Regards,
> 
>    On Monday, October 14, 2024 at 09:30:32 AM GMT+3, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:  
> 
> Hi @all,
> I hope you are all doing well, guys.
> Excuse my mind here is starting to get a'lil rusted and needs a jump start. How do I get a list of the first day of every week of the current calendar year in Omnis code? For example, what are the dates of every Monday from January to December? I've tried to look at the various date functions dpart, dtm, dtw but I'm getting lost.
> Any leads please.
> Martin.
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
> 
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com

_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com 
  


More information about the omnisdev-en mailing list