Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compare Date

Posted on 2006-10-31
3
Medium Priority
?
3,639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Assisted Solution

by:bloodredsun
bloodredsun earned 200 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

597 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