b89576658c2520c22306b8b8f635d73001af010c
FAQ/Questions/Adding-Custom-Time-Periods.md
| ... | ... | @@ -4,7 +4,9 @@ |
| 4 | 4 | |
| 5 | 5 | ##Adding Custom TimePeriods |
| 6 | 6 | |
| 7 | -Here is an example of how to add custom time spans to the filters. Apply this code within ``InitializeReporting()`` in your Global.asax. |
|
| 7 | +Here is an example of how to add custom time spans to the filters. Apply this code within [[InitializeReporting()|/FAQ/InitializeReporting]] in your Global.asax. |
|
| 8 | + |
|
| 9 | +###Example: Lunar Cycle |
|
| 8 | 10 | |
| 9 | 11 | ```csharp |
| 10 | 12 | //the if block prevents the key from being re-added to the list |
| ... | ... | @@ -13,6 +15,40 @@ if (!AdHocSettings.CustomTimePeriods.ContainsKey("Lunar Cycle")) { |
| 13 | 15 | } |
| 14 | 16 | ``` |
| 15 | 17 | |
| 18 | +Since we didn't specify a **StartDate**, Izenda will assume the server's current time as the **StartDate** of the time period. If we run a report with an **in time period** filter on OrderDate that used **lunar cycle** as its time period on March 4, 2015 at 3:46:58 PM, the query results of this would like similar to the below SQL: |
|
| 19 | + |
|
| 20 | +```sql |
|
| 21 | +SELECT TOP 100000 |
|
| 22 | +DATEPART(year, [dbo].[Invoices].[OrderDate]) AS 'Label', SUM([dbo].[Invoices].[Freight]) AS 'Value', DATEPART(month, [dbo].[Invoices].[OrderDate]) AS 'Separator' |
|
| 23 | +FROM [dbo].[Invoices] WITH(NOLOCK) |
|
| 24 | +WHERE ([dbo].[Invoices].[OrderDate] BETWEEN '2015-03-04T15:46:58.541' AND '2015-04-03T04:31:01.517') |
|
| 25 | +GROUP BY DATEPART(year, [dbo].[Invoices].[OrderDate]), DATEPART(month, [dbo].[Invoices].[OrderDate]) |
|
| 26 | +ORDER BY DATEPART(year, [dbo].[Invoices].[OrderDate]) ASC; |
|
| 27 | +``` |
|
| 28 | + |
|
| 29 | +###Example: Today |
|
| 30 | + |
|
| 31 | +We can also specify the start date. So if we wanted to get the results from just today and today is March 4, 2015, then we could craft a **TimePeriod** to do that. |
|
| 32 | + |
|
| 33 | +```csharp |
|
| 34 | +if(!AdHocSettings.CustomTimePeriods.ContainsKey("Today")) |
|
| 35 | +{ |
|
| 36 | + CustomTimePeriod today = new CustomTimePeriod("Today", new TimeSpan(23, 59, 59, 999), DateTime.Now.Date); |
|
| 37 | + AdHocSettings.CustomTimePeriods.Add("Today", today); |
|
| 38 | +} |
|
| 39 | +``` |
|
| 40 | + |
|
| 41 | +In this example, we specified the **StartDate** as today's date without any of the time information, which defaults to 0:00:00 (midnight). So if we query the results of the same report now, we would get: |
|
| 42 | + |
|
| 43 | +```sql |
|
| 44 | +SELECT TOP 100000 |
|
| 45 | +DATEPART(year, [dbo].[Invoices].[OrderDate]) AS 'Label', SUM([dbo].[Invoices].[Freight]) AS 'Value', DATEPART(month, [dbo].[Invoices].[OrderDate]) AS 'Separator' |
|
| 46 | +FROM [dbo].[Invoices] WITH(NOLOCK) |
|
| 47 | +WHERE ([dbo].[Invoices].[OrderDate] BETWEEN '2015-03-04T00:00:00.000' AND '2015-03-04T23:59:59.999') |
|
| 48 | +GROUP BY DATEPART(year, [dbo].[Invoices].[OrderDate]), DATEPART(month, [dbo].[Invoices].[OrderDate]) |
|
| 49 | +ORDER BY DATEPART(year, [dbo].[Invoices].[OrderDate]) ASC; |
|
| 50 | +``` |
|
| 51 | + |
|
| 16 | 52 | ##Modifying An Existing Time Period |
| 17 | 53 | |
| 18 | 54 | You may at any time modify your existing set of custom time periods. You cannot, however, modify built-in time periods this way. |
| ... | ... | @@ -20,4 +56,14 @@ You may at any time modify your existing set of custom time periods. You cannot, |
| 20 | 56 | ```csharp |
| 21 | 57 | CustomTimePeriod ctp = AdHocSettings.CustomTimePeriods["Lunar Cycle"]; |
| 22 | 58 | ctp.StartDate = DateTime.Now + ctp.Period; //passed by reference so the original list will update |
| 23 | -``` |
|
| ... | ... | \ No newline at end of file |
| 0 | +``` |
|
| 1 | + |
|
| 2 | +##Screenshots |
|
| 3 | + |
|
| 4 | +###Report Designer |
|
| 5 | + |
|
| 6 | + |
|
| 7 | + |
|
| 8 | +###Report Viewer |
|
| 9 | + |
|
| 10 | + |
|
| ... | ... | \ No newline at end of file |