Solved

Compare Date

Posted on 2006-10-31
3
3,632 Views
Last Modified: 2011-08-18
hi,

How can I compare today's date with database field date ? I want to do this in Javascript and throw alert if current date is less than database date ?? how

my DB field date is in this format presently : 2006-12-31 00:00:00.0


thx,
PH
0
Comment
Question by:princehyderabad
3 Comments
 
LVL 29

Assisted Solution

by:bloodredsun
bloodredsun earned 50 total points
ID: 17848318
It's a bit flakey to do in JavaScript (better to do it in Java) but here's an example of how to in JavaScript

    if ( new Date(document.frmTest.startDate.value) > new Date( <%= dbDateValue %> ) ){
        alert ("Start Date is greater");
    }

you will need to convert the db date to the correct string version so that JavaScript can understand it. For this you will need to use the SimpleDateFormatter in your Java code like this

Format formatter = new SimpleDateFormat("dd/MM/yyyy");
String s = formatter.format(date); //where date is your date object from the db
// s = "01/11/2006"



0
 

Author Comment

by:princehyderabad
ID: 17869449
if it is flakey to do in JS, lets make the way for JSP. Can u tell me how to do it then ...


<%
String restric-date = rs.getString("RESTRIC_DATE");
%>
<JAVASCRIPT...>
?? how to get current date either in java or javascript
?? how to format both date to one format and compare
???? how abt geting values in JSP code and comparing in JS. Bcoz I need to throw alter based on date user enter.

</JAVASCRIPT>
0
 
LVL 9

Accepted Solution

by:
ftaco96 earned 75 total points
ID: 17933161
<%
String restric-date = rs.getString("RESTRIC_DATE");
SimpleDateFormat fmtDate = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss.S");
Date dtNow = new Date();
Date dtRestricDate = fmtDate.parse(restric-date);

if (dtRestricDate.compareTo(dtNow) < 0) { %>
<SCRIPT...>
    alert("Your alert message here.");

</SCRIPT>
<%
}
%>
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 127
dateFashion java challenge 9 146
Limiting the number of characters a user can type in a text field 6 61
print map entry 34 72
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question