PDA

View Full Version : Choose the day the weeks start



Sera
24-Jan-2013, 04:01 AM
Hi,

Is it possible to choose the day the weeks start?

Here the week starts on Monday and the date picker shows a calendar starting on Sunday (see attached image)

6057

TIA

Garret Mott
24-Jan-2013, 07:59 AM
The calendar that is included with VDFQuery (popup_calendar) has a switch that lets you choose Sunday or Monday.

Oops - never mind - I missed that this was the Dynamic AI form (still getting used to that) - sorry!

Bob Cergol
24-Jan-2013, 09:39 AM
Hi Serafin,

Currently there is no provision for you to control week starting day on the date-picker style, or the calendar charts.

Oddly enough, the calendar charts do start with Monday -- which looks odd to us in the U.S. -- we like the date-picker format and would like the calendar charts to start with Sunday.

6059

I have sent a reminder to Cintac that this would be a nice feature to have.

Regards,
Bob

Eddy Kleinjan
24-Jan-2013, 10:34 AM
Hi Sarafín,

When I looked at the Calendar control using a browser debugger (Chrome in this case) I found that is was loaded from some JavaScript file called fnccal2.js. Analyzing that code, you will see that there is a variable declared named g_startDay (mind the casing!). This variable can be used to define the start day of the week. 'All we need to do' is change that value _after_ the fnccal2.js file has been loaded.

In Dynamic AI you can add some own Javascript code to reports under the 'Rules' tab when in design mode. While this is meant to be used to create some validation rules in case you would like to give user the ability to edit data using Dynamic AI, you can also use this to add some own code to reports. And it have to be said: When you make modifications here to reports: You're on your own!

When you woud add a line like this:
g_startDay = 1
to the Rules section you would think that this woud do the job. Wrong! The catch here is that the code in the Rules section is executed _before_ the fnccal2.js code is loaded. So our own code is executed too early. To fix that we should put the code in a function that is executed after the loading of the page is completed. My trick for this usually is the setTimout function of the browser. It allows you to set a timeout after which a function should be executed. When you supply a 0 as the timeout value (in miliseconds) then usually the function is executed _after_ the page is loaded. If this doesn't work, you can always try to increase the timeout value.

So the code you can add to your report in the Rules section is:

setTimeout(function(){ g_startDay = 1; }, 0);

This will set the value of g_startDay at the right point in time and show you a calendar that starts on Monday.

Eddy Kleinjan
Data Access Europe

60626063

Bo Andersen
29-Jan-2013, 05:29 AM
Nice hack Eddy :)

Benjamin
28-Mar-2018, 11:01 AM
I see that this is an old(er) thread but was this ever solved?
If so, where do I set the "Week Start"?

At my location we start the week on Sunday. The calendar selection shows me Sunday as the first day of the week. So far so good.
However, the preset filter defaults somewhat don't follow that same rule. When selecting the "Prev. Week" filter, is selects the Monday as the first day, not Sunday as seen in the calendar.

Can I influence this somehow?

Bob Cergol
28-Mar-2018, 12:47 PM
Eddy's 1 line of .js to put in rules tab solved the question posted by Sera about date-picker on date filters, so yes, I'd say this thread was 'solved'.

You are asking about something different, one among numerous pre-defined date functions that Dynamic AI allows you to use in fixed conditions or as defaults for date filters.

You'll notice that there are two previous week functions: one is previous work week. One starts with Monday, the other starts with Sunday.

If you can't find a predefined default to your liking you can easily roll your own using SQL DatePart command.

Bob

Benjamin
28-Mar-2018, 01:35 PM
Bob,
I have tested both and discovered "Prev. w. week" and "Prev. week" both resulted in setting 03/19/2018 (Monday) as the Start Date and both are returning 03/25/2018 (Sunday) as the stop date. Where am I going wrong?

You say I can build my own with SQL DatePart, where would I do that?

Bob Cergol
28-Mar-2018, 02:55 PM
I beg your pardon. My memory failed me regarding the definitions of "week" versus "work week". "Week" = 7 days starting with Monday. "Work Week = 5 days starting with Monday. I retested and i get 3/19-2018 through 3/25-2018 and 3/19-2018 through 3/23-2018 respectively.

This "starting with Monday" behavior stems from how SQL (at least MS-SQL) works. It numbers days 0 through 6, with 0 being Monday.

I guess someone, somewhere, somtime, thought "weekend" really meant the last two days of the week, else it would have been called week-bookends! :-)

You can see this by running this SQL

----Today
SELECT GETDATE() 'Today'
----Yesterday
SELECT DATEADD(d,-1,GETDATE()) 'Yesterday'
----First Day of Current Week
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) 'First Day of Current Week'
----Last Day of Current Week
SELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6) 'Last Day of Current Week'
----First Day of Last Week
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) 'First Day of Last Week'
----Last Day of Last Week
SELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6) 'Last Day of Last Week'
----First Day of Current Month
SELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) 'First Day of Current Month'
----Last Day of Current Month
SELECT DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()) +1,0))) 'Last Day of Current Month'
----First Day of Last Month
SELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) 'First Day of Last Month'
----Last Day of Last Month
SELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()) ,0))) 'Last Day of Last Month'
----First Day of Current Year
SELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0) 'First Day of Current Year'
----Last Day of Current Year
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()) +1,0))) 'Last Day of Current Year'
----First Day of Last Year
SELECT DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) 'First Day of Last Year'
----Last Day of Last Year
SELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()) ,0))) 'Last Day of Last Year'
----------
SELECT DATEADD(yy,-1,(DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE() ),0)))) 'First day of current month in previous year'
SELECT DATEADD(second,-1,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()) ,0))) 'Last Day of Last Month'


Cintac for sure won't be changing this "standard" behavior in version 6 of the product. In version 7 I'm told calendar presentations (not talking about date pickers here), will be user-definable regarding showing a U.S. style calendar with Sunday in the first column, versus the rest of the world that shows Monday in the first column.

As to your "where would I do that" question, it depends on what exactly your trying to accomplish. You started asking about passing date values in the URL to report filters, then about defaulting report filter values, then switched to view parameters, so I've lost track....

I guess if your ultimate goal is to have a report automatically run for some date range interval, and that interval needs to be dynamic based on today's date, then you'd use some sort of function like the ones in my SQL example above, and put it in the report's fixed condition, or in the where clause of whatever view is being used as the data source for the report.

As far as providing end-users with a choice at runtime and defaulting that choice to something not supported out-of-the-box, it can be rather more involved. You can use only very simplistic expressions to define a default value to a view parameter typed as a date. But report combo-type filter values can come from any column from another report.

I recall building for your company some years ago a custom drop-down list for a payroll period filter showing the date ranges in all the periods. Those periods were a dynamically moving window for something like 6 months. The drop-down values were coming from a list report based on some SQL view that was using date functions. Maybe you could find that report in your system and look at how it works.

Bob