• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Format date using jsp to save into mysql DB

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the problem i have. I have two textfields. Start date and end date. I use a date picker to enter the value into the textfields. The values are then stored into a mysql database. This part works fine. I got 3 fields in my database. A startdate, enddate and duration. My question is how do i find out the duration if i have two dates in two textfields.

Example

Textfield 1 : 13-06-2006
Textfield 2 : 16-06-2006
Duration = 3 days (How do i calculate this)

I solved the above using the below mentioned code.
<script type="text/javascript">
<!--
function checkdate() {
var begDate = new Date(document.demoform.dc1.value);
var endDate = new Date(document.demoform.dc2.value);
var difDate = endDate.getTime() - begDate.getTime();
var days = difDate / (24*60*60*1000);
alert(days);
}
//-->
</script>

The problem is it does not work with this format. DD-MM-YYYY. Is it possible for me to use jsp and find out the difference between the days and save it to the mysql database. Thank you for your help.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Managed to solve the problem.
 
We can walk to school together. And we can both read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic