Default Value in Date & Time Prompts

 To set the default value of a date prompt to yesterday’s date – or to any other date- you can use a javascript in the prompt page. IBM provides a small javascript code that you can use:
<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 = “08:00:00.000”;
return Time;
}
pickerControlPDateTime.setValue( subtractDay() );
timePickerPDateTime.setValue( subtractTime() );
</script>

You can also change the number of milliseconds and use the code for other relative dates. The problem with code is when you try to schedule the report with default value “yesterday” the code will not be executed. I will show you how to solve that issue in the next post.

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: