8 Replies Latest reply on Jan 10, 2017 12:35 AM by Stigge

# Calculate date from weeknr and day-name

Hi

Am trying for fun to build a time report application for myself. =)

But am a bit stuck on choosing a weeknumber then having Monday - Sunday as radio buttons, so by choosing lets say week 2 and choosing Monday

i need a variable that is telling me the date: 2017-01-09.

Do anyone know how to easly solve this ? =)

/Sti

• ###### 1. Re: Calculate date from weeknr and day-name

You calculate Week number with WeekOfYear function

To get todays date, have a script trigger setting a Global Field to Get(CurrentDate) when you start your solution

• ###### 2. Re: Calculate date from weeknr and day-name

This might work or be a starting point:

Let ( [

F1 = 2 ; //  Day of Week Radio button Field… in this example Day 2 which is a Monday

F2 = 3 ;  //  Week of the Year.. this example is week 3

F3 = Get ( CurrentDate ) ;

F4 = Year ( F3 ) ;

F5 = ( F2 * 7 ) + Date ( 1 ; 1 ; F4 ) + F1 ;

F6 = DayOfWeek ( F5 ) ;

F7 = If ( F6 = 1 ; 6 ; F6 - 2 ) ;

F8 = GetAsDate ( F5 - F7 )

] ; F8 )

This formula gives the starting date of the pay period for a Monday if that is what you wanted.

• ###### 3. Re: Calculate date from weeknr and day-name

Johan,

What do you mean ? dont get it ?

You calculate Week number with WeekOfYear function

I can only GET the weeknr with that function, not the date of the weeknr.

To get todays date, have a script trigger setting a Global Field to Get(CurrentDate) when you start your solution

Then it requeres to create each day as per day, i need to flexibility to create it when i want.

• ###### 4. Re: Calculate date from weeknr and day-name

Taylor,

Will try and see if i can =)

Edit: cant get it to work. only showing as a "?" :/ but thats when i use field values instead of F1 and F2.

thanks

• ###### 5. Re: Calculate date from weeknr and day-name

You also have to be careful as to what you mean by "the first week of the year". The first day of 2017 just so happened to fall on a Sunday. It will fall in the middle of the week for other years so your definition of the "first week" might not be the same as everyone else's or the same as that returned by the FileMaker function.

Frankly, selecting the week of the year, if that's a manual action instead of a value auto-selected via script, doesn't sound very user friendly. Most time entries in a time keeping solution are made on or close to the date being entered. Thus there are other auto-enter type options that might save you the trouble most of the time.

• ###### 6. Re: Calculate date from weeknr and day-name

philmodjunk his problem is that in Sweden we have Monday as first day of week, so we need to recalculate first day of the week. Not a big thing, but it would be nice if FM could see what country setting it is and automatically convert to Monday

• ###### 7. Re: Calculate date from weeknr and day-name

I understand your point about Monday being the first day of the week, but this is not something that I was attempting to address at all.

I'm questioning whether the entire approach here is really practical if the purpose is to enter a specific date into a field. Trying to remember the correct "week number" might not be so easy for the user. A system that auto-enters today's date as the default value to enter data under a specific date where the date field then comes with a calendar pop up would seem far simpler.

If entering a date for reporting purposes, again, knowing that you want week 300 and not week 299 might not always be an easy thing to know. Thus, other approaches that enable the user to pick from a list of dates (One date per week), or where the user selects a month and then a week might be easier to work with.

• ###### 8. Re: Calculate date from weeknr and day-name

Hi Phil,

Am considering to use the callender approach instead. wanted first to work with full weeks, but now i might just go pure dates instead. do to all the issues that working with weeks bring.

Thanks =)