Solved

Compare Date

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to view directory list in apache/tomcat 9 109
JSP Popup page 2 108
best way to search/remove a file from an EAR file 3 102
lessBy10  challenge 15 92
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

19 Experts available now in Live!

Get 1:1 Help Now