Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Dates difference in days javascript

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED] Dates difference in days javascript
 Login/Join
 
Platinum Member
posted
Hi

I have 2 calendar controls in YYMD format and I am trying to find difference in days so that I could alert if date range is more than 60 days.

I am using this logic.
var dt_1 = document.form1.DT1.value;
var dt_2 = document.form1.DT2.value;

var no_of_days = dt_2 - dt_1;

if (dt_1 == '' && dt_2 == '')
{
	alert("Please enter a range for Date");
}

if (dt_1 > dt_2)
{
	alert("FROM date cannot be greater than TO date");
}

alert(no_of_days);


Everything works but I dont get the number of days. It shows 'NaN' in the alert box when I try to get value in no_of_days.
Can someone help me on this?

Thank you

This message has been edited. Last edited by: Kerry,


WF 8.2.01 APP STUDIO
PDF,HTML,EXL2K,Active
 
Posts: 139 | Registered: July 21, 2011Report This Post
Expert
posted Hide Post
You really should try Google, 'javascript difference between two dates' -should provide links to the answer. Most likely the DT1 control is a text box, hence it's alphanumeric and alphanumeric - alphanumeric will most likely lead to NaN - the NaN property represents "Not-a-Number" value.

You need to convert the value of these text boxes to JavaScript date variables and then subtract, but Google will lead you to this.

Bonne chance.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Platinum Member
posted Hide Post
I tried few ways but doesn't work.
quote:
Originally posted by Francis Mariani:
You really should try Google, 'javascript difference between two dates' -should provide links to the answer. Most likely the DT1 control is a text box, hence it's alphanumeric and alphanumeric - alphanumeric will most likely lead to NaN - the NaN property represents "Not-a-Number" value.

You need to convert the value of these text boxes to JavaScript date variables and then subtract, but Google will lead you to this.

Bonne chance.


WF 8.2.01 APP STUDIO
PDF,HTML,EXL2K,Active
 
Posts: 139 | Registered: July 21, 2011Report This Post
Expert
posted Hide Post
How hard did you try?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>

<script type="text/javascript">

function Calc1()
{
var dt_1 = new Date(document.getElementById('DT1').value);
var dt_2 = new Date(document.getElementById('DT2').value);

//Set 1 day in milliseconds
var one_day = 1000 * 60 * 60 * 24;

//Calculate difference between the two dates, and convert to days
var no_of_days = (dt_2 - dt_1) / (one_day);

if (dt_1 == '' && dt_2 == '')
{
	alert("Please enter a range for Date");
}

if (dt_1 > dt_2)
{
	alert("FROM date cannot be greater than TO date");
}

alert(no_of_days);
}
</script>
</head>

<body>
<input id="DT1" type=text value="2010/10/23">
<input id="DT2" type=text value="2010/10/24">

<input type="button" onClick="Calc1();" value="Calculate">
</body>
</html>


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
As Francis has stated in his example, the key is to condert the date text in the control to a javascript date by using the new Date() command.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Expert
posted Hide Post
And I should have stated that the difference between two dates is returned in milliseconds. To find out how many days, divide by the number of milliseconds in one day.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] Dates difference in days javascript

Copyright © 1996-2020 Information Builders