Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
java script problem with date
birt0825
I am trying to write a java script to pass a date range based on parameters.
My code can't go through.
Can someone check for me to see where is the problem?
Thanks very much for your help.
var RightNow = new Date();
var month = ((RightNow.getMonth() + 1) < 10) ? "0" + (RightNow.getMonth() + 1) : (RightNow.getMonth()+1);
var day = (RightNow.getDate() < 10) ? "0" + RightNow.getDate() : RightNow.getDate();
var year = RightNow.getFullYear();
var shortyear=year.substr(3,2);
var MyDate = month + "/" + day + "/" + year;
// we need a new month variable for month-1, also formatted correctly
var lastmonth = ((month - 1) < 10) ? "0" + (month - 1) : (month - 1);
var lastmonthBegin=lastmonth + "/01/" + year;
//// now grab the last day of the month (30, 31? we don't know!)
var moend = new Date(year, (month - 1), 0);
this.queryText =this.queryText +" and createdate >'"+ lastmonth + "/" + moend.getDate() + "/" + shortyear +"'";
Find more posts tagged with
Comments
mwilliams
Hi birt0825,
If you store your queryText in a variable and display it in the report, does your date look like it should?
birt0825
thanks. I think my problem is how to add a java script for date.
I tried to use the following code in the reportDegign initialize:
var RightNow = new Date();
var month = ((RightNow.getMonth() + 1) < 10) ? "0" + (RightNow.getMonth() + 1) : (RightNow.getMonth()+1);
var day = (RightNow.getDate() < 10) ? "0" + RightNow.getDate() : RightNow.getDate();
var year = RightNow.getFULLYear();
Then report can't compile:it showed script error.
What is the correct format for handling date in scripts?
mwilliams
Where do your parameters come in? Does the user select a date from a list? Enter a date in a text box parameter? Let me know this and your BIRT version. I'll try to make you an example of ways to do it.
birt0825
We need to automate the parameters.
user only input one number, for example: 1 for date range for last month;2--for date range in last year;
or 2010/12 for data in 2010 december;
I need to write out the begindate and enddate for each period.
Do you have a sample for writing java scripts to handling dates?
birt0825
My Birt version is 2.3.2. Thanks.
mwilliams
Take a look at this report. It covers the first 2 options. The third option should be pretty straight forward, I just didn't take the time to implement it for this quick example. Let me know if you have any questions on how to do it and I'll try to help!
birt0825
Thanks. It works.
mwilliams
Great! Let us know whenever you have questions.