Solved

Compare Date

Posted on 2006-10-31
3
3,629 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now