Solved

Compare Date

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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