Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8946671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:34:42+00:00 2026-06-15T12:34:42+00:00

I have a date field in database which store just date without time. Now

  • 0

I have a date field in database which store just date without time. Now I want to know the number of days difference in current date and my date field while displaying that in jsp page.

so I should have like

 databaseDate(2012-11-30) - currentDate(2012-11-27)  = 3 days
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:34:42+00:00Added an answer on June 15, 2026 at 12:34 pm

    There’s nothing like that in standard JSTL. A custom EL function would be your best bet.

    First implement some static methods which performs the job:

    public final class Functions {
    
        private Functions() {}
    
        public static int daysBetween(Date before, Date after) {
            // ...
        }
    
        public static int daysUntilToday(Date date) {
            // ...
        }
    
    }
    

    If you register it as follows in /WEB-INF/functions.tld:

    <?xml version="1.0" encoding="UTF-8" ?>
    <taglib 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
        version="2.1">
    
        <tlib-version>1.0</tlib-version>
        <short-name>Custom_Functions</short-name>
        <uri>http://example.com/functions</uri>
    
        <function>
            <name>daysBetween</name>
            <function-class>com.example.Functions</function-class>
            <function-signature>boolean daysBetween(java.util.Date, java.util.Date)</function-signature>
        </function>
        <function>
            <name>daysUntilToday</name>
            <function-class>com.example.Functions</function-class>
            <function-signature>boolean daysUntilToday(java.util.Date)</function-signature>
        </function>
    </taglib>
    

    then you’ll be able to use it as follows, provided that #{bean.date} returns a fullworthy java.util.Date:

    <%@taglib uri="http://example.com/functions" prefix="f" %>
    
    ${f:daysUntilToday(bean.date)} days
    

    The implementation is free to your choice. I’d personally prefer Joda Time:

    public static int daysBetween(Date before, Date after) {
        return Days.daysBetween(new DateTime(before.getTime()), new DateTime(after.getTime())).getDays();
    }
    
    public static int daysUntilToday(Date date) {
        return Days.daysBetween(new DateTime(date.getTime()), new DateTime()).getDays();
    }
    

    Or if you’re restricted to standard Java API, fall back to the well known Calendar boilerplate (unfortunately, JSR-310 didn’t made it into Java 7, we’ve to wait for Java 8):

    public static int daysBetween(Date before, Date after) {
        Calendar c1 = createCalendarWithoutTime(before);
        Calendar c2 = createCalendarWithoutTime(after);
        int days = 0;
    
        for (;c1.before(c2); days++) {
            c1.add(Calendar.DATE, 1);
        }
    
        return days;
    }
    
    public static int daysUntilToday(Date date) {
        return daysBetween(date, new Date());
    }
    
    private static Calendar createCalendarWithoutTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge database (800MB) which consists of a field called 'Date Last
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
I have a sqlite3 database with a datetime field, the format of the date/time
I want a Django model to have a date field in which the year,
I want to store a date value in a MySQL database. I have one
I have a custom UserType which stores a date/time value in a TIMESTAMP field
In my grid data store, I have a date field which contains data coming
I have a date field in a mysql database which I am trying to
I have a Timestamp field in a WebSQL database that is stored like: /Date(1340420400000)/
I have a table with a field of type date within a MySQL database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.