- IBM Cognos 8 Report Studio Cookbook
- Abhishek Sanghani
- 650字
- 2021-08-06 17:15:51
Manipulating Date Time control
There is a report that allows users to filter on Shipment Date Time using Date Time control. By default, Cognos selects current date and midnight as the date and time.
Report Studio allows you to override this with another static default value. However, business usually runs the report for the end of previous business day (5 PM).
In this recipe, we will learn how to change the default date and time for a Date Time control to the end of the previous business day.
Getting ready
Create a dummy report that shows sales quantity by shipment day. Define filter on shipment day.
How to do it...
- We will start by adding a date and time control to the report. For that add a new prompt page.
- From insertable objects, drag Date & Time Prompt on the prompt page. Connect it to the Shipment Day filter using appropriate parameter in the prompt wizard.
- Now select the prompt and set its Name property to shipmentDate.
- Now add an HTML item to the prompt footer after the Finish button. Define it as:
<script> function subtractDay () { var dtToday = new Date(); var dtYesterday = new Date( dtToday - 86400000 ); // NOTE 86400000 = 24 hours * 60 (minutes per hour) * 60 (seconds per minute) * 1000 milliseconds per second) var strYesterday = [dtYesterday.getUTCFullYear(), dtYesterday.getMonth()+1, dtYesterday.getDate()].join("-"); return strYesterday; } function subtractTime () { var Time = "17:00:00.000"; return Time; } pickerControlshipmentDate.setValue( subtractDay() ); timePickershipmentDate.setValue( subtractTime() ); </script>
- Run the report to test. You will see that the value of the 'Date Time control' is set to previous day, 5 PM by default.
How it works...
Here we use standard JavaScript functions to work out the date of the previous day. Please note that this date is computed based on system date on user's machine.
Then we apply this date to the 'Date & Time control' using a pickerControl<name>
object. Also we set the time to 5 PM using setValue
function of timePicker<name>
object.
You can similarly do more date and string manipulations to find First
of
Month
, Last
of
Month
, and so on. I found the following script on the Internet for generating commonly used dates.
<script language="JavaScript" runat="SERVER"> var today = new Date(); var thisYear = today.getYear(); var thisMonth = today.getMonth(); var thisDay = today.getDate(); function rw(s1, s2) { Response.Write("<tr><td>"+s1+"</td><td>"+s2+"</td></tr>"); } Response.Write("<table border='1'>"); rw("Today:", today.toDateString()); //Years var fdly = new Date(thisYear - 1, 0, 1); rw("First day of last year:", fdly.toDateString()); var ldly = new Date(thisYear, 0, 0); rw("Last day of last year:", ldly.toDateString()); var fdty = new Date(thisYear, 0, 1); rw("First day of this year:", fdty.toDateString()); var ldty = new Date(thisYear + 1, 0, 0); rw("Last day of this year:", ldty.toDateString()); var fdny = new Date(thisYear + 1, 0 ,1); rw("First day of next year:", fdny.toDateString()); var ldny = new Date(thisYear + 2, 0, 0); rw("Last day of next year:", ldny.toDateString()); //Months var fdlm = new Date(thisYear, thisMonth - 1 ,1); rw("First day of last month:", fdlm.toDateString()); var ldlm = new Date(thisYear, thisMonth, 0); rw("Last day of last month:", ldlm.toDateString()); rw("Number of days in last month:", ldlm.getDate()); var fdtm = new Date(thisYear, thisMonth, 1); rw("First day of this month:", fdtm.toDateString()); var ldtm = new Date(thisYear, thisMonth + 1, 0); rw("Last day of this month:", ldtm.toDateString()); rw("Number of days in this month:", ldtm.getDate()); var fdnm = new Date(thisYear, thisMonth + 1, 1); rw("First day of next month:", fdnm.toDateString()); var ldnm = new Date(thisYear, thisMonth + 2, 0); rw("Last day of next month:", ldnm.toDateString()); rw("Number of days in next month:", ldnm.getDate()); Response.Write("</table>"); </script>
There's more...
You can write more sophisticated functions to work out the previous working day instead of just the previous day.
See also
You can mix this technique with other recipes in this chapter to tie the selection event with button click or radio buttons, that is, a particular date/time can be selected when user clicks on the button or selects a radio button.
- IBM Cognos 8 Report Studio Cookbook
- Moldflow模流分析與工程應用
- Learning VirtualDub: The complete guide to capturing, processing and encoding digital video
- AutoCAD Civil 3D 2018 場地設計實例教程
- CakePHP 1.3 Application Development Cookbook
- 板繪教室:SAI零基礎日系動漫插畫入門教程
- Vue 企業開發實戰
- PostgreSQL Replication
- Seam 2 Web Development: LITE
- Photoshop CC 2017 淘寶美工設計實例教程
- Learning the Yahoo! User Interface library
- Photoshop 2020實戰從入門到精通(超值版)
- Photoshop CC中文版基礎教程
- HBase企業應用開發實戰
- AutoCAD 2016從入門到精通